title: How do I marshal a struct that contains a variable-sized array to C#?
body: <p>How do I marshal this C++ type?</p>
  
  <p>The ABS_DATA structure is used to associate an arbitrarily long data block with the length information. The declared length of the <code>Data</code> array is 1, but the actual length is given by the <code>Length</code> member.</p>
  
  <pre><code>typedef struct abs_data {
    ABS_DWORD Length;
    ABS_BYTE Data[ABS_VARLEN];
  } ABS_DATA;
  </code></pre>
  
  <p>I tried the following code, but it's not working. The data variable is always empty and I'm sure it has data in there.</p>
  
  <pre><code>[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Ansi)]
      public struct abs_data
      {
          /// ABS_DWORD-&gt;unsigned int
          public uint Length;
  
          /// ABS_BYTE[1]
         [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 1)]
          public string Data;
      }
  </code></pre>