lundi 17 octobre 2016

create assembly run time by using Reflection.Emit. in mvc5

I want to create an assembly at run time like this:

AssemblyName an = new AssemblyName("ImanAssembly");
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Save);
ModuleBuilder mb = ab.DefineDynamicModule(an.Name, an.Name + ".exe");
TypeBuilder tb = mb.DefineType("Product", TypeAttributes.Public);
FieldBuilder fb = tb.DefineField("ProName", typeof(string), FieldAttributes.Public);
Type t = tb.CreateType();
ab.Save(an.Name + ".exe");

But I get this error in last line of my code:

An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Update: i solve that by run VS as admin...but why i cant find my created assembly in bin folder???? where can i find it ?





Aucun commentaire:

Enregistrer un commentaire