Bugzilla – Bug 315978
[TESTCASE] Calling InvokeMember on a Activator.CreateInstance type on a pinvoke member throws a TargetInvocationException
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by grompf@sublimeintervention.com 2004-09-08 21:17:12 MST ---- The following code throws: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object in (unmanaged) (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[]) in <0x0008c> (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[]) in <0x000f4> System.Reflection.MonoMethod:Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.Cul tureInfo) --- End of inner exception stack trace --- in <0x00174> System.Reflection.MonoMethod:Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.Cul tureInfo) in <0x00700> System.MonoType:InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[],System.Reflection. ParameterModifier[],System.Globalization.CultureInfo,string[]) in <0x00078> System.Type:InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[]) in <0x00134> Apple.Foundation.Test:Main (string[]) While it works on ms.net using System; using System.Reflection; using System.Reflection.Emit; using System.Runtime.InteropServices; using System.Threading; namespace Apple.Foundation { public class Test { static Assembly generated = null; static Assembly GenerateAssembly() { AssemblyName an = new AssemblyName(); an.Name = "Apple.ObjCMessaging"; AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run); ModuleBuilder module = builder.DefineDynamicModule(an.Name); TypeBuilder typebuilder = module.DefineType("Generator", TypeAttributes.Public); MethodBuilder method = typebuilder.DefinePInvokeMethod("printf", "msvcrt.dll", MethodAttributes.PinvokeImpl | MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, typeof(void), new Type[]{typeof(string)}, CallingConvention.Winapi, CharSet.Auto); typebuilder.CreateType(); module.CreateGlobalFunctions(); return module.Assembly; } static Assembly TypeResolve(object sender, ResolveEventArgs args) { Console.WriteLine ("Returning resolver..."); if (generated == null) generated = GenerateAssembly(); return generated; } static void Main (string[] args) { AppDomain.CurrentDomain.TypeResolve += new ResolveEventHandler (TypeResolve); Type t = System.Type.GetType("Generator"); Console.WriteLine ("TYPE:={0}", t); object o = Activator.CreateInstance(t); t.InvokeMember("printf", BindingFlags.InvokeMethod|BindingFlags.Public|BindingFlags.Static, null, o, new object[]{"Hello!"}); } } } ---- Additional Comments From vargaz@freemail.hu 2004-09-09 09:03:29 MST ---- I think this one is fixed as well. ---- Additional Comments From grompf@sublimeintervention.com 2004-09-09 15:31:28 MST ---- this is fixed with the other patch Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>OSX 10.3.4</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other".