我们的测试机器上有个很奇怪的bug。错误是:
系统。来自程序集“activeviewer(…)”的类型“DummyItem”中的方法“SetShort”没有实现。
我就是不明白为什么。SetShort在DummyItem类中,我甚至重新编译了一个版本,写入事件日志,只是为了确保它不是部署/版本控制问题。奇怪的是,调用代码甚至不调用SetShort方法。
我们的测试机器上有个很奇怪的bug。错误是:
系统。来自程序集“activeviewer(…)”的类型“DummyItem”中的方法“SetShort”没有实现。
我就是不明白为什么。SetShort在DummyItem类中,我甚至重新编译了一个版本,写入事件日志,只是为了确保它不是部署/版本控制问题。奇怪的是,调用代码甚至不调用SetShort方法。
当前回答
另一种可能是在依赖关系中混合发布和调试构建。例如,程序集A依赖于程序集B, A是在调试模式下构建的,而GAC中的B副本是在发布模式下构建的,反之亦然。
其他回答
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>
在那之后,两个错误都消失了,项目建立起来了。
以下是我对这个错误的看法。
添加了一个extern方法,但我的粘贴是错误的。DllImportAttribute被放到一个注释出来的行。
/// <returns>(removed for brevity lol)</returns>[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindowVisible(IntPtr hWnd);
确保属性实际包含在源代码中解决了这个问题。
作为补充:如果更新用于生成假程序集的nuget包,也会发生这种情况。假设您安装了一个nuget包的V1.0版本,并创建了一个假程序集“fakeLibrary.1.0.0.0.Fakes”。接下来,更新到nuget包的最新版本,比如v1.1,它向接口添加了一个新方法。Fakes库仍在寻找该库的1.0版本。只需移除假组装和再生它。如果这是问题所在,这可能会解决它。
在最近的一次windows更新后,我收到了这个错误。我设置了一个从接口继承的服务类。该接口包含一个返回ValueTuple的签名,这是c#中的一个相当新的特性。
我所能猜到的是,windows更新安装了一个新的,但即使显式引用它,更新绑定重定向,等等…最终的结果只是将方法的签名更改为“标准”的东西。
为我解决的问题是添加以下到ProjectReference和/或PackageReference以及<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>在正在加载的程序集中:
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
这使我的项目文件看起来像这样:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<!-- For a package -->
<ItemGroup>
<PackageReference Include="SomePackage" Version="x.x.x.x">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>
<!-- For a project -->
<ItemGroup>
<ProjectReference Include="..\SomeProject\SomeProject.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
</Project>