I'm generating new dynamic type and wan't to create it's instance. But when actually create instantiation code, it's fails with exception: No parameterless constructor defined for this object.
My code is the following:
AssemblyBuilder aBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("dfsdfsdf"), AssemblyBuilderAccess.Run);
ModuleBuilder mBuilder = aBuilder.DefineDynamicModule("dsadsadasdasda");
TypeBuilder typeBlank = mBuilder.DefineType("dasvvvvvvvv", TypeAttributes.Class | TypeAttributes.Public);
ConstructorBuilder cb = typeBlank.DefineDefaultConstructor(MethodAttributes.Public);
Type t = cb.GetType();
var item = Activator.CreateInstance(t); // <--- Error appear in this line.
What is wrong there?
Aucun commentaire:
Enregistrer un commentaire