我们的测试机器上有个很奇怪的bug。错误是:
系统。来自程序集“activeviewer(…)”的类型“DummyItem”中的方法“SetShort”没有实现。
我就是不明白为什么。SetShort在DummyItem类中,我甚至重新编译了一个版本,写入事件日志,只是为了确保它不是部署/版本控制问题。奇怪的是,调用代码甚至不调用SetShort方法。
我们的测试机器上有个很奇怪的bug。错误是:
系统。来自程序集“activeviewer(…)”的类型“DummyItem”中的方法“SetShort”没有实现。
我就是不明白为什么。SetShort在DummyItem类中,我甚至重新编译了一个版本,写入事件日志,只是为了确保它不是部署/版本控制问题。奇怪的是,调用代码甚至不调用SetShort方法。
当前回答
我一直在想这个问题…… 这里的许多答案都很好地解释了问题是什么,但没有解释如何解决问题。
解决方案是手动删除项目发布目录中的bin文件。它将清理所有引用,并强制项目使用最新的dll。
我不建议使用发布工具的Delete功能,因为这可能会使IIS失效。
其他回答
当我的集成测试项目试图加载一个不包含接口依赖项解析的DLL时,我遇到了这个错误:
集成测试项目(参考主项目,但不是 StructureMap) 主要项目(引用StructureMap项目-使用 类构造函数中的接口) StructureMap项目(IoC - For().Use();)
这将导致抛出错误,因为它无法找到具体的实现。我在测试配置中排除了DLL,错误消失了
作为补充:如果更新用于生成假程序集的nuget包,也会发生这种情况。假设您安装了一个nuget包的V1.0版本,并创建了一个假程序集“fakeLibrary.1.0.0.0.Fakes”。接下来,更新到nuget包的最新版本,比如v1.1,它向接口添加了一个新方法。Fakes库仍在寻找该库的1.0版本。只需移除假组装和再生它。如果这是问题所在,这可能会解决它。
如果使用assembly . loadfrom (String)加载程序集,并且正在引用已经使用assembly . load (Byte[])加载的程序集,也可能导致此错误。
例如,你嵌入了主应用程序的引用程序集作为资源,但你的应用程序从特定的文件夹加载插件。
你应该使用Load而不是LoadFrom。下面的代码将完成这项工作:
private static Assembly LoadAssemblyFromFile( String filePath )
{
using( Stream stream = File.OpenRead( filePath ) )
{
if( !ReferenceEquals( stream, null ) )
{
Byte[] assemblyData = new Byte[stream.Length];
stream.Read( assemblyData, 0, assemblyData.Length );
return Assembly.Load( assemblyData );
}
}
return null;
}
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.
我在Visual Studio Pro 2008中看到了这一点,当时两个项目构建了具有相同名称的程序集,一个是类库SDF.dll,另一个是使用程序集名称sdf.exe引用程序库。 当我更改引用程序集的名称时,异常消失了