[Mono-bugs] [Bug 590042] New: Dynamically generated methods/delegates using custom marshalling with p/invoke crash the application

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Mar 21 16:59:05 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=590042

http://bugzilla.novell.com/show_bug.cgi?id=590042#c0


           Summary: Dynamically generated methods/delegates using custom
                    marshalling with p/invoke crash the application
    Classification: Mono
           Product: Mono: Runtime
           Version: 2.6.x
          Platform: x86-64
        OS/Version: Mac OS X 10.5
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: interop
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: goldencrystal at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Description of Problem:
When a delegate type is created dynamically, and the delegate's signature
(actually, its Invoke method's signature) uses an ICustomMarshaler, the mono
runtimes crashes on a failed assertion.
There seems to be some related problem with dynamically generated p/invoke
methods too, but only under specific conditions. (Actually, the condition seems
to be giving the (marshaled) parameter any value other than null)


Steps to reproduce the problem:
1. Create a new type inheriting System.MulticastDelegate insinde of a
DynamicAssembly
2. Add the standard constructor for delegate types
3. Implement the Invoke method, and apply a MarshalAsAttribute with
CustomMarshaler to (at least) one of the parameters.
4. Create the actual type and instantiate a delegate
5. Use the instantiated delegate for p/invoke

6. Or: Create a dynamic P/Invoke method with at least one custom marshaler as
parameter, and invoke it with something else than null as value.


Actual Results:
**
ERROR:marshal.c:5271:emit_marshal_custom: assertion failed: (mtype != NULL)
Stacktrace:

  at (wrapper managed-to-native) object.__icall_wrapper_mono_delegate_to_ftnptr
(object) <0x00004>
  at (wrapper managed-to-native) object.__icall_wrapper_mono_delegate_to_ftnptr
(object) <0x00004>
  at (wrapper managed-to-native) EmitMarshalTestCase.Program.dummyMethod
(System.Delegate) <IL 0x00003, 0x00026>
  at EmitMarshalTestCase.Program.Main (string[]) [0x0025a] in
/Users/Fabien/Documents/MonoDevelop
Projects/EmitMarshalTestCase/EmitMarshalTestCase/EmitMarshalTestCase.cs:131
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object
(object,intptr,intptr,intptr) <IL 0x0001d, 0x00043>
L'application s'est terminée suite au signal: SIGIOT

Expected Results:
No error. (Verified on MS.NET's runtime)

How often does this happen? 
Always.

Additional Information:
1. It seems that when a delegate with the same signature (and mashaling) is
generated by the C# compiler (csc or gmcs) and then instantiated (the
instantiation is the important part) and used with the same p/invoke method,
the dynamically created delegate won't crash thereafter. However, this
completely defeats the purpose of a dynamically created delegate.
2. From the code where the assertions fails, it seems that there is a problem
in resolving the custom marshaler's type from the extracted method's metadata,
but the exact origin of the problem is difficult to locate without a very good
understanding of the mono runtime internals.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list