我试图动态创建另一个程序集中的类CommandDrawing
的实例。 CommandDrawing
类的默认构造函数包含对静态方法的调用,这些静态方法位于同一个集合中的另一个类中。创建动态类,但是,当它改掉运行在构造函数中的静态方法调用它倒了,出现异常:动态创建具有构造函数的类,该构造函数调用另一个静态类方法
Exception has been thrown by the target of an invocation. TypeInitializeException`The type initializer for threw an exception.
我必须在这两个类,如果是如何加载?
我用下面的代码来创建,我已经成功地使用之前和工作类时静态方法调用是不是有:
Assembly assemblyCommandDrawing = System.Reflection.Assembly.LoadFile(@"D:\ManifoldInspections.dll");
Type typeCommandDrawing = assemblyCommandDrawing.GetType("InspectionDetails.CommandDrawing");
object cmd = System.Activator.CreateInstance (typeCommandDrawing, new object[] { drawing, DrawingBaseDetail });
的CommandDrawing
默认构造函数看起来像下面 - 注意UtilityMapControl.SetupDrawingTableTemplate
是静态方法我打电话,它倒在这里:
public CommandDrawing(Manifold.Interop.Drawing p_Drawing, InspectionDetails.DrawingBaseDetail p_ClassDetailTemplate)
{
this.Drawing = p_Drawing;
//this.ClassDetailTemplate = p_ClassDetailTemplate.GetType();
this.ClassDetailTemplate = p_ClassDetailTemplate;
ManifoldInspections.Utility.UtilityMapControl.SetupDrawingTableTemplate(this.Drawing, p_ClassDetailTemplate);
}
你能提供生成动态类的代码吗? – ivowiblo
是否有内部异常?如果是这样,那是什么?您不应该需要显式加载这两个类。 –
ivowiblo - 抱歉,我正在动态创建一个类的实例,而不是类。 – gisWeeper