[Mono-bugs] [Bug 80240][Nor] New - StructLayout attribute for C# types passed to managed code

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Dec 12 12:14:50 EST 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 wsf at fultondesigns.co.uk.

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

--- shadow/80240	2006-12-12 12:14:50.000000000 -0500
+++ shadow/80240.tmp.12721	2006-12-12 12:14:50.000000000 -0500
@@ -0,0 +1,75 @@
+Bug#: 80240
+Product: Mono: Runtime
+Version: 1.2
+OS: 
+OS Details: XP SP2
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: interop
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: wsf at fultondesigns.co.uk               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: StructLayout attribute for C# types passed to managed code
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+Marshalling of C# types to unmanaged code does not work using the mono
+interpreter
+
+Steps to reproduce the problem:
+1. Run the runme.exe executable on Windows using runme.exe, then run 'mono
+runme.exe'
+2. Note that when run under mono, the program aborts.
+
+
+Actual Results:
+A dialog pops up with -
+** ERROR **: Type System.DateTime which is passed to unmanaged code must
+have a StructLayout attribute aborting...
+
+Expected Results:
+When the executable is run directly (compiled by Microsoft's csc or Mono's
+mcs), the program works as expected with the following output -
+$ ./runme.exe
+--------
+TheDateHelper.SetDate in:28/05/2004 00:00:00
+UnmarshalTheDate 29/05/2004 00:00:00
+TheDateHelper.SetDate out:29/05/2004 00:00:00
+Date: 29/05/2004 00:00:00
+
+How often does this happen? 
+Everytime - tested on windows (mono 1.2) and linux (mono 1.1)
+
+Additional Information:
+I'll attach a zipfile with the source and compiled binaries. It includes a
+Makefile to recompile the code on cygwin should this be required (not
+really necessary though).
+
+Description of what the code does:
+The idea here is to marshal a managed class (System.DateTime) by reference
+for use from the unmanaged side. From runme.cs:
+
+        DateTime d = new DateTime(2004, 5, 28);
+        example.byRef(ref d);
+        ... use d ...
+
+example.byRef() ultimately calls into unmanaged code:
+
+  [DllImport("example", EntryPoint="CSharp_byRef")]
+  public static extern void byRef(ref DateTime jarg1);
+
+and the unmanaged code needs to read the date and modify it so the modified
+version can be used in the managed code.
+
+From within the unmanaged code (CSharp_byRef() in example_wrap.cxx), the
+date is extracted and set via delegate/callbacks back into the managed code.
+
+The relevant code is in the .cs files and the example_wrap.cxx files. Feel
+free to ignore the .i files as these are just swig files used to create the
+relevant code.


More information about the mono-bugs mailing list