[Mono-bugs] [Bug 45182][Blo] New - Fixed size structure marshaling issue

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Fri, 20 Jun 2003 05:51:51 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by jlaban@wanadoo.fr.

http://bugzilla.ximian.com/show_bug.cgi?id=45182

--- shadow/45182	Fri Jun 20 05:51:51 2003
+++ shadow/45182.tmp.24799	Fri Jun 20 05:51:51 2003
@@ -0,0 +1,54 @@
+Bug#: 45182
+Product: Mono/Runtime
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: jlaban@wanadoo.Fr               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Fixed size structure marshaling issue
+
+There is a marshaling issue when using fixed size marshaling. string 
+marshalling is incorrect.
+
+Here a sample code to demonstrate de problem :
+
+---------------------------------------
+using System;
+using System.Runtime.InteropServices;
+
+namespace Test {
+	[StructLayout(LayoutKind.Sequential, Size=32)]
+	public struct MyStruct {
+		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=16)]
+		public string test;
+	}
+
+	public class Dummy {
+		public static void Main() {
+			MyStruct dummy1 = new MyStruct();
+			dummy1.test = "0123456789";
+
+			IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf
+(typeof(MyStruct)));
+			Marshal.StructureToPtr(dummy1, ptr, false);
+            
+			for(int i=0; i<16; i++) {
+				byte c = Marshal.ReadByte(ptr, i);
+
+				if( (i < 10 && c != 0x30 + i) || (i >= 10 
+&& c != 0) )
+					throw new Exception("Marshaling 
+error");
+			}
+		}
+	}
+}