【发布时间】:2012-08-09 19:42:29
【问题描述】:
我有一个很奇怪的问题。我在 dll 中定义了一个接口,如下所示:
public interface IKreator2
{
string Name { get; set; }
string Description { get; set; }
INotifyPropertyChanged Settings { get; set; }
InfiniRenderJob Job { get; set; }
UserControl UI { get; set; }
void Init();
//void OnClose();
}
如果我在我的 WPF 应用程序中链接到此 dll,调试器会在加载时崩溃(内部错误:调试器中的未处理异常::HandleIPCEvent,ID=0x246)。如果我使用“调试非托管代码”调试应用程序,我会收到以下错误:
- 0x76977945 (KernelBase.dll) 中的第一次机会异常 InfiniRender.Host.exe:Microsoft C++ 异常:EETypeLoadException 在内存位置 0x0029c5b8。
- 0x76977945 (KernelBase.dll) 中的第一次机会异常 InfiniRender.Host.exe:Microsoft C++ 异常:[rethrow] 在内存中 位置 0x00000000。
- 出现“System.TypeLoadException”类型的第一次机会异常 在 InfiniRender.Host.exe 中
- “System.TypeLoadException”类型的未处理异常发生在 InfiniRender.Host.exe 附加信息:Nicht abstrakte einer Schnittstelle 中的 Nicht-.cctor-Methode。
目前我完全不知道发生了什么。甚至没有实现接口,也没有类使用它。如果我将方法“Init”注释掉,一切都会按预期工作。 有什么想法吗??
[编辑] 这是 Interface init 方法的 MSIL:
.method public hidebysig newslot virtual
instance void Init() cil managed
{
// Code size 96 (0x60)
.maxstack 3
.locals init ([0] class [mscorlib]System.Exception CS$0$0__ex)
IL_0000: ldsfld class [NLog]NLog.Logger '<>z__LoggingImplementationDetails'::l14
IL_0005: callvirt instance bool [NLog]NLog.Logger::get_IsTraceEnabled()
IL_000a: brfalse.s IL_001b
IL_000c: ldsfld class [NLog]NLog.Logger '<>z__LoggingImplementationDetails'::l14
IL_0011: ldstr "Entering: InfiniRender.IKreator2.Init()"
IL_0016: call instance void [NLog]NLog.Logger::Trace(string)
.try
{
IL_001b: newobj instance void [mscorlib]System.NotSupportedException::.ctor()
IL_0020: throw
IL_0021: ldsfld class [NLog]NLog.Logger '<>z__LoggingImplementationDetails'::l14
IL_0026: callvirt instance bool [NLog]NLog.Logger::get_IsTraceEnabled()
IL_002b: brfalse.s IL_003c
IL_002d: ldsfld class [NLog]NLog.Logger '<>z__LoggingImplementationDetails'::l14
IL_0032: ldstr "Leaving: InfiniRender.IKreator2.Init()"
IL_0037: call instance void [NLog]NLog.Logger::Trace(string)
IL_003c: leave.s IL_005f
} // end .try
catch [mscorlib]System.Exception
{
IL_003e: ldsfld class [NLog]NLog.Logger '<>z__LoggingImplementationDetails'::l14
IL_0043: callvirt instance bool [NLog]NLog.Logger::get_IsWarnEnabled()
IL_0048: brfalse.s IL_005d
IL_004a: stloc.0
IL_004b: ldsfld class [NLog]NLog.Logger '<>z__LoggingImplementationDetails'::l14
IL_0050: ldstr "An exception occurred:\n{0}"
IL_0055: ldloc.0
IL_0056: call instance void [NLog]NLog.Logger::Warn(string,
object)
IL_005b: rethrow
IL_005d: leave.s IL_005f
} // end handler
IL_005f: ret
} // end of method IKreator2::Init
在我看来,应该归咎于 NLog?直到今天,NLog 才出现任何问题...
【问题讨论】:
-
该接口的原始 IL 说明了什么?
-
你可以在某处上传复制品吗?
-
你是如何消费这个界面的?您的错误意味着一些非托管代码。此外,
TypeLoadException实例很可能不是由于接口,而是由于实现接口的代码。