gpt4 book ai didi

c# - 我得到 "Non abstract, non-.cctor-method in an interface"的原因是什么?

转载 作者:太空狗 更新时间:2023-10-29 21:54:58 27 4
gpt4 key购买 nike

我有一个很奇怪的问题。我在 dll 中定义了一个接口(interface),如下所示:

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++ 异常:[重新抛出] 在内存中位置 0x00000000。
  • 发生“System.TypeLoadException”类型的第一次机会异常在 InfiniRender.Host.exe
  • “System.TypeLoadException”类型的未处理异常发生在InfiniRender.Host.exe 附加信息:Nicht abstrakteNicht-.cctor-Methode iner Schnittstelle。

目前我完全不知道发生了什么。甚至没有接口(interface)的实现,也没有类使用它。如果我将方法“Init”注释掉,一切都会按预期进行。有什么想法吗??

[编辑]这是接口(interface)初始化方法的 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 才出现任何问题......

最佳答案

所以,这里的罪魁祸首是“Postsharp.Diagnostics.Toolkit”,它向接口(interface)方法声明添加了代码,导致调试器困惑。

感谢所有提供帮助的人!

关于c# - 我得到 "Non abstract, non-.cctor-method in an interface"的原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11578677/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com