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

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

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


当前回答

在我的例子中,它帮助重置WinForms工具箱。

当在设计器中打开窗体时,我得到了异常;然而,编译和运行代码是可能的,并且代码的行为符合预期。异常发生在实现我引用的库之一的接口的本地UserControl中。更新此库后出现错误。

这个UserControl列在WinForms工具箱中。可能Visual Studio保留了库的一个过时版本的引用,或者在某个地方缓存了一个过时的版本。

下面是我如何从这种情况中恢复过来的:

右键单击WinForms工具箱,然后单击上下文菜单中的重置工具箱。(这将从工具箱中删除自定义项)。 在我的例子中,“工具箱”项被恢复到默认状态;但是,“工具箱”中缺少指针箭头。 关闭Visual Studio。 在我的案例中,Visual Studio以一个违反异常终止并中止。 重新启动Visual Studio。 现在一切都很顺利。

其他回答

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

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

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

I got this error because I had a class in an assembly 'C' which was on version 4.5 of the framework, implementing an interface in assembly 'A' which was on version 4.5.1 of the framework and serving as the base class to assembly 'B' which was also on version 4.5.1 of the framework. The system threw the exception while trying to load assembly 'B'. Additionally, I had installed some nuget packages targeting .net 4.5.1 on all three assemblies. For some reason, even though the nuget references were not showing in assembly 'B', it was building successfully.

事实证明,真正的问题是程序集引用了包含接口的nuget包的不同版本,并且接口签名在不同版本之间发生了变化。

我刚刚将一个解决方案从MVC3升级到MVC5,并开始从我的单元测试项目中收到相同的异常。

检查所有的引用寻找旧文件,最终发现我需要做一些bindingRedirects Mvc,在我的单元测试项目。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

我在以下场景中收到此错误。

程序集A和程序集B都引用了System.Web.Mvc Version 3.0.0.0 程序集A引用程序集B,并拥有实现程序集B接口的类,这些类的方法返回来自System.Web.Mvc的类。 程序集A升级到System.Web.Mvc版本4.0.0.0 程序集C运行下面的代码(FertPin.Classes。Contact包含在Assembly A):

var target = Assembly.GetAssembly(typeof(FertPin.Classes.Contact));

对我来说,修复是将程序集B中的System.Web.Mvc引用升级到4.0.0.0。现在看来很明显了!

感谢原来的海报!

当我的集成测试项目试图加载一个不包含接口依赖项解析的DLL时,我遇到了这个错误:

集成测试项目(参考主项目,但不是 StructureMap) 主要项目(引用StructureMap项目-使用 类构造函数中的接口) StructureMap项目(IoC - For().Use();)

这将导致抛出错误,因为它无法找到具体的实现。我在测试配置中排除了DLL,错误消失了