title: How can a structure with reserved space be marshalled?
body: <p>Problem:</p>
  
  <p>I have a struct of a fixed size that I'm trying to marshal. This struct contains a number of useful fields for the current version of the struct and a specified amount of unused space at the end that is reserved for future modifications.</p>
  
  <p><em>How should I design this structure so that the size of the reserved space will be automatically updated when I modify the structure?</em></p>
  
  <p>While the following would solve my problem</p>
  
  <pre><code>'Variable size structure
  &lt;StructLayout(LayoutKind.Sequential, Pack:=1)&gt;
  Structure UsefulData
      Dim foo As SByte
      Dim bar As Integer
      Dim foobar As Short
  End Structure
  
  Const MAX_SIZE As Integer = 20
  
  'Fixed size structure
  &lt;StructLayout(LayoutKind.Sequential, Pack:=1, Size:=MAX_SIZE&gt;
  Structure Data
      Dim current As UsefulData
      &lt;MarshalAs(UnmanagedType.ByValArray, SizeConst:=MAX_SIZE-System.Runtime.InteropServices.Marshal.SizeOf(GetType(UsefulData)))&gt;
      Dim reserved As SByte()
  End Structure
  </code></pre>
  
  <p>but doesn't compile as <code>System.Runtime.InteropServices.Marshal.SizeOf(GetType(UsefulData))</code> is not a constant expression. Any ideas?</p>