我们的测试机器上有个很奇怪的bug。错误是:

系统。来自程序集“activeviewer(…)”的类型“DummyItem”中的方法“SetShort”没有实现。

我就是不明白为什么。SetShort在DummyItem类中,我甚至重新编译了一个版本,写入事件日志,只是为了确保它不是部署/版本控制问题。奇怪的是,调用代码甚至不调用SetShort方法。


当前回答

我在WCF服务中得到了这个,因为选择了x86构建类型,导致箱子在bin\x86下而不是bin下。选择Any CPU会导致重新编译的dll到达正确的位置(我不会详细说明这是如何发生的)。

其他回答

I had the same problem. I figured out that my assembly, which is loaded by the main program, had some references with "Copy Local" set to true. These local copies of references were looking for other references in the same folder, which did not exist because the "Copy Local" of other references was set to false. After the deletion of the "accidentally" copied references the error was gone because the main program was set to look for correct locations of references. Apparently the local copies of the references screwed up the sequence of calling because these local copies were used instead of the original ones present in the main program.

重要的信息是,出现此错误是因为缺少加载所需程序集的链接。

另一种情况是,有符号程序集的版本不正确。这不是这种疾病的正常症状,但这是我患病的情况

asp.net项目包含程序集A和程序集B, B是强命名的 程序集A使用Activator。CreateInstance加载程序集C(即没有对单独构建的C的引用) C是引用程序集B的较旧版本构建的

希望这能帮助到一些人,我花了很长时间才弄明白。

当我之前在一个程序集的单元测试期间启用了代码覆盖时,我也得到了这个错误。由于某种原因,Visual Studio“缓冲”了这个特定DLL的旧版本,即使我已经更新了它以实现新版本的接口。禁用代码覆盖消除了错误。

在我的例子中,我试图使用TypeBuilder创建一个类型。TypeBuilder。CreateType抛出此异常。我最终意识到我需要添加MethodAttributes。在调用TypeBuilder时,将属性虚拟化。帮助实现接口的方法的DefineMethod。这是因为如果没有这个标志,该方法不会实现接口,而是实现一个具有相同签名的新方法(甚至没有指定MethodAttributes.NewSlot)。

Our problem solved with updating windows! Our web application is on .Net 4.7.1 and c# 7.0. As we tested in different windowses, we understood that the problem will be solved by updating windows. Indeed, the problem was seen in windows 10 (version 1703) and also in a windows server 2012(not updated in last year). After updating both of them, the problem was solved. In fact, the asp.net minor version(the third part of the clr.dll version in C:\Windows\Microsoft.NET\Framework64\v4.0.30319 ) was changed a bit after the update.