title: Marshal struct in struct from c# to c++
body: <p>I have the following structures in C# and C++.</p>
  
  <p><strong>C++:</strong></p>
  
  <pre><code>struct TestA
  {
      char* iu;       
  };
  
  struct TestB
  {   
      int cycle1;
      int cycle2; 
  };
  
  struct MainStruct
  {   
      TestA test;
      TestB test2;
  };
  </code></pre>
  
  <p><strong>C#:</strong></p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack = 1)]
  internal struct TestA
  {
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 36)]
      private string iu;
  
      public TestA(Guid Iu)
          : this()
      {
          iu = Iu.ToString("D");
      }
  }
  
  [StructLayout(LayoutKind.Sequential), Serializable]
  internal struct TestB
  {
      int cycle1;
      int cycle2; 
  }
  
  [StructLayout(LayoutKind.Sequential)]
  internal struct MainStruct
  {        
      private TestA testA;    
      private TestB testB;
  
      private MainStruct(TestA Test_A) : this()
      {
         testA = Test_A;
      }
  
      public static MainStruct Initial(TestA Test_A, TestB Test_B)
      {
          return new MainStruct(Test_A)
          {
              testB = Test_B
          };
      }            
  }
  </code></pre>
  
  <p>Marhsaling data had worked until I had to write struct which combines two others (MainStruct). C++ doesn't receive data. On c++ site I get: "Error reading characters of string"</p>
  
  <p>Could anyone shed light on it? What is wrong? On c# or c++ site?</p>