title: How to determine the size of an instance?
body: <p>I have set my project to accept unsafe code and have the following helper Class to determine the size of an instance:</p>
  
  <pre><code>struct MyStruct
      {
          public long a;
          public long b;
      }
  
  public static class CloneHelper
      {
          public unsafe static void GetSize(BookSetViewModel book)
          {
              long n = 0;
  
              MyStruct inst;
              inst.a = 0;
              inst.b = 0;
              n = Marshal.SizeOf(inst);
          }
  }
  </code></pre>
  
  <p>This works perfectly fine with a struct. However as soon as I use the actual class-instance that is passed in: </p>
  
  <pre><code>public unsafe static void GetSize(BookSetViewModel book)
          {
              long n = 0;
  
  
              n = Marshal.SizeOf(book);
          }
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Type 'BookSetViewModel' cannot be marshaled as an unmanaged structure;
    no meaningful size or offset can be computed.</p>
  </blockquote>
  
  <p>Any idea how I could fix this?
  Thanks,</p>