[Mono-bugs] [Bug 78492][Nor] New - Marshal.PtrToStruct doesn't create objects under some cirumstances

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue May 23 12:08:05 EDT 2006


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 toscen at web.de.

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

--- shadow/78492	2006-05-23 12:08:05.000000000 -0400
+++ shadow/78492.tmp.5723	2006-05-23 12:08:05.000000000 -0400
@@ -0,0 +1,80 @@
+Bug#: 78492
+Product: Mono: Compilers
+Version: 1.1
+OS: unknown
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: toscen at web.de               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Marshal.PtrToStruct doesn't create objects under some cirumstances
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+see source in additional information.
+
+Steps to reproduce the problem:
+1. 
+2. 
+3. 
+
+Actual Results:
+
+System.NullReferenceException when trying to access HWRights array in source.
+
+Expected Results:
+
+Proper HWRights array object.
+
+How often does this happen? 
+
+always
+
+Additional Information:
+
+using System;
+using System.Runtime.InteropServices;
+using System.Collections;
+
+
+namespace TestProj
+{
+	[StructLayout (LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
+  	public class TData
+  	{
+    	[MarshalAs (UnmanagedType.ByValArray, SizeConst = 2)]
+    	public TAppRights[] AppRight;
+	}  
+
+
+  	[StructLayout (LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
+  	public struct TAppRights
+  	{
+    	[MarshalAs (UnmanagedType.ByValArray, SizeConst = 2)]
+    	public short[] HWRights;
+  	};
+ 
+
+	class MainClass
+	{
+		public static void Main(string[] args)
+		{
+			TData data;
+			byte[] ba = new byte[8];
+
+			GCHandle handle = GCHandle.Alloc (ba, GCHandleType.Pinned);
+			data = (TData)Marshal.PtrToStructure (handle.AddrOfPinnedObject (),
+typeof(TData));
+			Console.WriteLine(data.AppRight[0].HWRights[0]);
+		}
+	}
+}


More information about the mono-bugs mailing list