[Mono-bugs] [Bug 64915][Maj] New - UnmanagedType.CustomMarshaler works incorrectly in mono 1.0
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 31 Aug 2004 10:15:26 -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 ddmk@mail.ru.
http://bugzilla.ximian.com/show_bug.cgi?id=64915
--- shadow/64915 2004-08-31 10:15:26.000000000 -0400
+++ shadow/64915.tmp.28211 2004-08-31 10:15:26.000000000 -0400
@@ -0,0 +1,185 @@
+Bug#: 64915
+Product: Mono: Runtime
+Version: unspecified
+OS:
+OS Details: Windows XP
+Status: NEW
+Resolution:
+Severity: 004 Four hours
+Priority: Major
+Component: packaging
+AssignedTo: duncan@ximian.com
+ReportedBy: ddmk@mail.ru
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: UnmanagedType.CustomMarshaler works incorrectly in mono 1.0
+
+Please fill in this template when reporting a bug, unless you know what
+you are doing.
+Description of Problem:
+I have implemented custom marshaler as following
+ public class MyMarshaler : ICustomMarshaler
+ {
+ public void CleanUpManagedData(Object obj)
+ {
+ //WrapperInterface.ToNativeR((MyType)obj);
+ Console.WriteLine("-------------CLEARING MANAGED
+(nothing) "+((MyType)obj).GetNATobj());
+ }
+
+ public void CleanUpNativeData(IntPtr nativeData)
+ {
+ Console.WriteLine("-------------CLEARING
+NATIVE "+nativeData);
+ WrapperInterface.DelRef(nativeData);}
+
+ public int GetNativeDataSize(){ return -1;}
+
+ public IntPtr MarshalManagedToNative(Object obj)
+ {
+ Console.WriteLine("-------------MARSHAL TO
+NATIVE "+((PluginObject)obj).GetAllocNATobjT());
+ return WrapperInterface.ToNativeR((PluginObject)
+obj);
+ }
+
+ public Object MarshalNativeToManaged(IntPtr nativeObj)
+ {
+ Console.WriteLine("-------------MARSHAL TO
+MANAGED "+nativeObj);
+ return WrapperInterface.ToNET(nativeObj);
+ }
+
+ public static ICustomMarshaler GetInstance(string cookie){
+ return mInstance;}
+
+ private static MyMarshaler mInstance = new MyMarshaler
+();
+
+ }
+
+//seems to be some of this attributes ignored ...
+[return : MarshalAs(UnmanagedType.CustomMarshaler,MarshalTypeRef = typeof
+(MyMarshaler))] public delegate MyType D0(IntPtr obj);
+
+//seems to be some of this attributes ignored ...
+[return : MarshalAs(UnmanagedType.CustomMarshaler,MarshalTypeRef = typeof
+(MyMarshaler))]
+ [DllImport(dll_name)] static private extern MyType W32347_22863_0
+(IntPtr obj);
+
+// not used in first bug but will used later (this part loaded normally
+without attribute LAYOUT)
+
+[DllImport(dll_name)] static private extern void W32346_223421_2(IntPtr
+obj, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof
+(MyMarshaler))] MyType a);
+public delegate void D2(IntPtr obj,[MarshalAs
+(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MyMarshaler))]
+MyType a);
+
+
+
+if MyType has no attribute [StructLayout(LayoutKind.Sequential)]
+Mono Failed at starup with error
+"*** ERROR marshal.c:2580 (mono_marshal_get_managet_wrapper) assertion
+failed :
+((klass->flags&TYPE_ATTRIBUTE_LAYOUT_MASK)!=TYPE_ATTRIBUTE_AUTO_LAYOUT)
+
+Microsoft .NET works correctly NOT THROWING EVEN EXCEPTION
+becouse i defined my Marshaler so it's no need to check for LAYOUT
+THIS IS FIRST BUG
+
+
+IF attribute present when results of one exe on mono and .NET differs
+Microsoft .NET result(presents of LAYOUT attribute is not affected):
+
+-------------MARSHAL TO MANAGED 1605808
+Version 1
+name Ismp
+To Native 1609208
+ plugin by interface 2
+0
+3
+From .NET arrray: 35 0
+Test Descr=sampe c++ plugin
+-------------CLEARING MANAGED(nothing) 1605808
+ref count : 0
+-------------MARSHAL TO MANAGED 119687464
+getting native object
+-------------MARSHAL TO MANAGED 119687464
+-------------CLEARING NATIVE 119687464
+tranferring net object to native
+-------------MARSHAL TO NATIVE 1606896
+To Native 1606896
+native : Getting NET object
+tranferring net object to native (return)
+-------------MARSHAL TO NATIVE 1606896
+To Native 1606896
+-------------CLEARING MANAGED(nothing) 1606896
+Getted object 1884f0 3
+returning from native
+-------------CLEARING NATIVE 1606896
+control return
+-------------CLEARING MANAGED(nothing) 119687464
+null object
+from NATIVE 50 35 0
+gmm version 1
+Trying to Start 1
+end
+wrapper object 00188DF8 destroyed
+wrapper object 001884F0 destroyed
+wrapper object 001880B0 destroyed
+destroying plugin 07224928 dispose ? 0
+
+MONO 1.0 result:
+-------------MARSHAL TO MANAGED 25411592
+Version 1
+name Ismp
+To Native 25422344
+ plugin by interface 2
+0
+3
+From .NET arrray: 0 0
+Test Descr=sampe c++ plugin
+ref count : 0
+-------------MARSHAL TO MANAGED 29697840
+getting native object
+-------------MARSHAL TO MANAGED 29697840
+tranferring net object to native
+-------------MARSHAL TO NATIVE 25422800
+To Native 25422800
+native : Getting NET object
+tranferring net object to native (return)
+Getted object 1850848 0
+returning from native
+-------------CLEARING NATIVE 25422800
+control return
+-------------MARSHAL TO MANAGED 0
+null object
+from NATIVE 0 35 18289848 //ARRAY TEST FAILED 61134 is not fixed on 1.0
+gmm version 1
+Trying to Start 1
+end
+wrapper object 0183EA08 destroyed
+wrapper object 0183C008 destroyed
+wrapper object 0183EBD0 destroyed
+
+
+It seems to CleanUpManagedData not called at all and CleanUpNativeData
+called only ones but Microsoft call Clean Symmetrical to Marshal (for 1
+marshal 1 clean)
+
+May be attribute [return : MarshalAs
+(UnmanagedType.CustomMarshaler,MarshalTypeRef = typeof(MyMarshaler))]
+ignored?? it will be answer to both bugs...
+
+I used very big programm but if you very need a small bugtest i try to
+write it....
+
+
+
+How often does this happen?
+everytime