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

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

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


当前回答

我在运行单元测试时也遇到了这个问题。应用程序运行良好,没有错误。 在我的案例中,问题的原因是我关闭了测试项目的构建。 重新启用我的测试项目的构建解决了这些问题。

其他回答

在最近的一次windows更新后,我收到了这个错误。我设置了一个从接口继承的服务类。该接口包含一个返回ValueTuple的签名,这是c#中的一个相当新的特性。

我所能猜到的是,windows更新安装了一个新的,但即使显式引用它,更新绑定重定向,等等…最终的结果只是将方法的签名更改为“标准”的东西。

我在使用Autofac和大量动态程序集加载时遇到了这个错误。

在执行Autofac解析操作时,运行库将无法加载其中一个程序集。错误消息抱怨程序集'ImplementationAssembly'中的'MyType'类型的方法'MyMethod'没有实现。在Windows Server 2012 R2虚拟机上运行时出现问题,但在Windows 10或Windows Server 2016虚拟机上没有出现问题。

ImplementationAssembly引用System.Collections.Immutable 1.1.37,并包含IMyInterface<T1,T2>接口的实现,该接口在单独的definentationassembly中定义。defintionassembly引用System.Collections.Immutable 1.1.36。

“未实现”的IMyInterface<T1,T2>中的方法具有类型为IImmutableDictionary<TKey, TRow>的参数,该参数在System.Collections.Immutable中定义。

在程序目录中找到的System.Collections.Immutable的实际副本是版本1.1.37。在我的Windows Server 2012 R2虚拟机上,GAC包含System.Collections.Immutable 1.1.36的副本。在Windows 10和Windows Server 2016上,GAC包含System.Collections.Immutable 1.1.37的副本。只有当GAC包含较旧版本的DLL时,才会发生加载错误。

因此,程序集加载失败的根本原因是对System.Collections.Immutable的引用不匹配。接口定义和实现具有看起来相同的方法签名,但实际上依赖于不同版本的System.Collections。不可变,这意味着运行时不考虑实现类与接口定义匹配。

添加以下绑定重定向到我的应用程序配置文件修复了这个问题:

<dependentAssembly>
        <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.37.0" newVersion="1.1.37.0" />
</dependentAssembly>

我刚刚将一个解决方案从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>

在我的例子中,我以前在repo之外的兄弟文件夹中引用了一个mylib项目——让我们称之为v1.0。

|-- myrepo
|    |-- consoleApp
|    |-- submodules
|         |-- mylib (submoduled v2.0)
|-- mylib (stale v1.0)

后来我做了正确的,并通过一个git子模块使用它-让我们称之为v2.0。 然而,一个项目consoleApp没有正确更新。它仍然在我的git项目之外引用旧的v1.0项目。

令人困惑的是,尽管*。csproj显然是错误的,并且指向v1.0, Visual Studio IDE将路径显示为v2.0项目! F12来检查接口和类也去了v2.0版本。

编译器放在bin文件夹中的程序集是v1.0版本,因此令人头疼。

IDE对我撒谎的事实让我很难意识到这个错误。

解决方案:从ConsoleApp中删除项目引用并读取它们。

一般提示:从头重新编译所有程序集(如果可能的话,当然不能用于nuget包),并检查bin\debug文件夹中的日期时间戳。任何过时的程序集都是你的问题。

I have yet another esoteric solution to this error message. I upgraded my target framework from .Net 4.0 to 4.6, and my unit test project was giving me the "System.TypeLoadException...does not have an implementation" error when I tried to build. It also gave a second error message about the same supposedly non-implemented method that said "The 'BuildShadowTask' task failed unexpectedly." None of the advice here seemed to help, so I searched for "BuildShadowTask", and found a post on MSDN which led me to use a text editor to delete these lines from the unit test project's csproj file.

<ItemGroup>
  <Shadow Include="Test References\MyProject.accessor" />
</ItemGroup>

在那之后,两个错误都消失了,项目建立起来了。