[Mono-bugs] [Bug 42240][Nor] New - MarshalAs(UnmanagedType.ByValArray) truncates array
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Thu, 1 May 2003 21:46:10 -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 dave@sanderman.org.
http://bugzilla.ximian.com/show_bug.cgi?id=42240
--- shadow/42240 Thu May 1 21:46:10 2003
+++ shadow/42240.tmp.8886 Thu May 1 21:46:10 2003
@@ -0,0 +1,61 @@
+Bug#: 42240
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 8.0
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: dave@sanderman.org
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: MarshalAs(UnmanagedType.ByValArray) truncates array
+
+Description of Problem:
+
+A class field marked as MarshalAs(UnmanagedType.ByValArray) with a
+SizeConst will end up trimmed of trailing zero bytes.
+
+
+Steps to reproduce the problem:
+
+----------------------
+using System;
+using System.Runtime.InteropServices;
+
+namespace Test
+{
+ public class Test
+ {
+ [StructLayout(LayoutKind.Sequential, Pack=1)]
+ class BugStruct
+ {
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
+ public byte[] bogus;
+ }
+
+ public static unsafe void Main(string[] args)
+ {
+ byte[] data = new byte[] {0,0,0,1,0,0,0,0};
+ fixed (byte *pb = data)
+ {
+ BugStruct bs = (BugStruct)Marshal.PtrToStructure(new IntPtr(pb),
+typeof(BugStruct));
+ Console.WriteLine("bs.bogus.Length is {0}", bs.bogus.Length);
+ }
+ }
+ }
+}
+-------
+
+
+Actual Results:
+on mono 0.23: bs.bogus.Length is 4
+
+Expected Results:
+on msft cli: bs.bogus.Length is 8