c# - Problems with generation of dynamic code -


this code gif one exception: invitation exception, please help, i do not know what will happen, i think add that because he Works when I push onto stack outsers, and when I push for Laurel it does not work, thanks

  Fixed zero main (string [] args) {AppDomain dominioAplicacion = System Threading.Thread.GetDomain (); Assembly name nombre_Del_Ensamblado = New assembly name ("ASS"); AssemblyBuilder ensambladoBld = dominioAplicacion.DefineDynamicAssembly (nombre_Del_Ensamblado, AssemblyBuilder and.); Modulebuilder moduleblend = ensambladoBld.DefineDynamicModule ("& lt; MOD"); TypeBuilder claseContenedoraBld = moduloBld.DefineType ("clay cantonadora"); MethodBuilder mainBld = claseContenedoraBld.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (Zero), type. Alight type); ILGenerator il = mainBld.GETILGenerator (); Fieldbuilder Campbold = Clientendorald.Diffinfeld ("X", Typef (Int.), FieldAttives.public; FieldAttivats.Static); IL Amit (Open Seeds. LDC_I4, 2); IL Amit (Open Seeds St.Field, Campbellland); Fieldbuilder Complex 1 = Clientendorald.Definfield ("x1", typef (int), field attendants public; field etatives; static); IL Amit (Open Seeds. LDC_I4, 2); IL Amit (Open Seeds. STFeld, Campbell 1); IL Amit (Open Seeds. LDFTN, Campbellland); //il.Emit(OpCodes.Unbox, typeof (int)); //il.Emit(OpCodes.Stloc_0); Il.Emit (OpCodes.Ldloc_0); IL Amit (Open Seeds. LDFTN, Camblod 1); //il.Emit(OpCodes.Unbox, typeof (int)); Il.Emit (OpCodes.Stloc_1); Il.Emit (OpCodes.Ldloc_1); //il.Emit(OpCodes.Box, typeof (int)); //il.Emit(OpCodes.Ldftn, campoBld1); //il.Emit(OpCodes.Unbox, typeof (int)); Il.Emit (OpCodes.Add); Il.Emit (OpCodes.Pop); //il.Emit(OpCodes.Stsfld, campoBld1); Il.Emit (OpCodes.Ret); Type T = Clay Contributor. Crap. Object ptInstance = Activator.CreateInstance (T, new type [] {}); T.InvokeMember ("Main", BindingFlag.Invok Mode | Binding Flag. Static | Binding Falagues. Public, Blank, ptInstance, New Object [0]); Var x = T. Gatefield ("x"); } Your IL is just illegal, the exception is not great, but you can see the intestines of the JIT compiler Opcodes. Ldsftn does not have to  not  which you think does that, you will need Ldsfld to load the area. I really can not understand what code you are trying to write but it should be close. This is not crashing in any way:    Fieldbuilder Campobild = Clientendorald.Definfield ("x", Typef (int), FieldAttives.Published; FieldAttivats.Static); IL Amit (Open Seeds. LDC_I4, 2); IL Amit (Open Seeds St.Field, Campbellland); Fieldbuilder Complex 1 = Clientendorald.Definfield ("x1", typef (int), field attendants public; field etatives; static); IL Amit (Open Seeds. LDC_I4, 2); IL Amit (Open Seeds. STFeld, Campbell 1); IL Amit (Open Seeds. Lidsfeld, Campbellland); IL Amit (Opsods. Lidsfeld, Campbell 1); Il.Emit (OpCodes.Add); Il.Emit (OpCodes.Pop); Il.Emit (OpCodes.Ret);  

The best way to find out what the IL is to use is to write your code for the first time in C #, then it looks like IL to separate from Ildasm.exe.


Comments