[Mono-bugs] [Bug 47295][Nor] Changed - Marshal.StructureToPtr fails with dynamically-created MulticastDelegate subclasses

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Sat, 2 Aug 2003 20:23:46 -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 mathpup@mylinuxisp.com.

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

--- shadow/47295	Sat Aug  2 20:22:26 2003
+++ shadow/47295.tmp.13284	Sat Aug  2 20:23:46 2003
@@ -1,14 +1,14 @@
 Bug#: 47295
 Product: Mono/Runtime
 Version: unspecified
-OS: 
+OS: unknown
 OS Details: 
 Status: NEW   
 Resolution: 
-Severity: 
+Severity: Unknown
 Priority: Normal
 Component: misc
 AssignedTo: mono-bugs@ximian.com                            
 ReportedBy: mathpup@mylinuxisp.com               
 QAContact: mono-bugs@ximian.com
 TargetMilestone: ---
@@ -61,6 +61,89 @@
 How often does this happen?  
  
 Always 
  
  
 Additional Information:
+
+------- Additional Comments From mathpup@mylinuxisp.com  2003-08-02 20:23 -------
+Attaching and showing test case... 
+ 
+using System; 
+using System.Reflection; 
+using System.Reflection.Emit; 
+using System.Runtime.InteropServices; 
+ 
+ 
+public class Testing 
+{ 
+    public static void Method(int value) 
+    { 
+        Console.WriteLine( "Method( {0} )", value ); 
+    } 
+ 
+ 
+    [StructLayout(LayoutKind.Sequential)] 
+    internal struct DelegateList 
+    { 
+        internal Delegate del; 
+    } 
+ 
+ 
+    public static void Main() 
+    { 
+        // Create a dynamic assembly and module to contain the 
+        // subclass of MulticastDelegate that we will create 
+ 
+        AssemblyName asmName = new AssemblyName(); 
+        asmName.Name = "DynamicAssembly"; 
+ 
+        AssemblyBuilder asmBuilder = 
+            AppDomain.CurrentDomain.DefineDynamicAssembly( 
+                asmName, AssemblyBuilderAccess.Run ); 
+ 
+        ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
+( "DynamicModule" ); 
+ 
+        TypeBuilder typeBuilder = modBuilder.DefineType( "MyType", 
+            TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed, 
+            typeof( System.MulticastDelegate ) ); 
+ 
+        ConstructorBuilder cb = typeBuilder.DefineConstructor( 
+            MethodAttributes.Public | MethodAttributes.HideBySig | 
+            MethodAttributes.RTSpecialName | MethodAttributes.SpecialName, 
+            CallingConventions.Standard, 
+            new Type[] { typeof(Object), typeof (IntPtr) } ); 
+ 
+        cb.SetImplementationFlags( MethodImplAttributes.Runtime | 
+MethodImplAttributes.Managed ); 
+ 
+        MethodBuilder mb = typeBuilder.DefineMethod( 
+            "Invoke", 
+            MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.
+HideBySig, 
+            typeof(void), 
+            new Type[] { typeof(int) } ); 
+ 
+        mb.SetImplementationFlags( MethodImplAttributes.Runtime | 
+MethodImplAttributes.Managed ); 
+ 
+ 
+        // Create an instance of the delegate type and invoke it -- just to test 
+ 
+        Type myDelegateType = typeBuilder.CreateType(); 
+        Delegate d = Delegate.CreateDelegate( myDelegateType, typeof
+( Testing ), "Method" ); 
+        d.DynamicInvoke( new object[] { 8 } ); 
+ 
+ 
+ 
+        DelegateList delegateList = new DelegateList(); 
+        delegateList.del = d; 
+        IntPtr ptr = Marshal.AllocHGlobal( Marshal.SizeOf( delegateList ) ); 
+ 
+        // The execption seems to occur at this statement: 
+        Marshal.StructureToPtr( delegateList, ptr, false ); 
+    } 
+ 
+} 
+