2012-05-29 4 views
1

다른 어셈블리에있는 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); 
} 
+0

동적 클래스를 생성하는 코드를 제공 할 수 있습니까? – ivowiblo

+0

내부 예외가 있습니까? 그렇다면 무엇입니까? 명시 적으로 두 클래스를 모두로드 할 필요는 없습니다. –

+0

ivowiblo - 죄송합니다. 저는 클래스가 아닌 클래스의 인스턴스를 동적으로 생성하고 있습니다. – gisWeeper

답변

1

아마도 종속성을로드 할 수 없습니다. 형식 이니셜 라이저가 발생할 수있는 다른 어셈블리의 형식을 사용하는 경우 LoadFile이 예상 한 것처럼 종속성을 해결하지 않기 때문입니다. MSDN says :

LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does.

그래서 내가 대신 LoadFileLoadFrom을 사용하는 것이 좋습니다.

+0

미안하지만 Botz300도 작동하지 않습니다. 같은 오류로 실패했습니다. – gisWeeper

관련 문제