当程序集位于 GAC 中时,Visual Studio 单元测试会抛出 MissingMethodException?
我的应用程序包含一段在组件服务内部执行的代码,因此我们需要在 GAC 中注册我们的业务规则层(及其依赖项)。 这些依赖项之一是 FooCore.dll,它包含对整个应用程序可见的类和服务。
一切都工作正常,直到我向 FooCore 中的类添加了一个新方法。 现在,当我运行单元测试时,任何调用此新方法的测试都会引发 MissingMethodException,即使我使用最新版本的程序集更新 GAC 也是如此。 唯一的修复方法是在运行测试之前从 GAC 中删除 FooCore。
我尝试了以下操作:
- 重建整个解决方案,刷新 GAC 中的内容,然后运行测试 = 失败
- 在测试项目中删除并重新添加 FooCore 程序集引用 = 失败
- 确保 FooCore 在属性中设置为“复制本地” = 失败
什么我可以做些什么来确保 VSTS 从显式定义的位置加载引用的程序集,而不是从 GAC 加载?
My application contains a piece of code that executes inside of Component Services, so we need to register our business rules layer (and its dependencies) in the GAC. One of those dependencies is FooCore.dll, which contains classes and services visible to the entire app.
Everything was working fine, until I added a new method to a class in FooCore. Now, when I run my unit tests, any test that calls this new method throws a MissingMethodException, even if I update the GAC with the latest version of the assembly. The only fix is to remove FooCore from the GAC before running the tests.
I've tried the following things:
- Rebuilt entire solution, refreshed stuff in GAC, then ran tests = failure
- Removed and re-added FooCore assembly reference in test project = failure
- Ensured that FooCore is set as "Copy Local" in properties = failure
What can I do to ensure that VSTS loads referenced assemblies from their explicitly defined location, rather than from the GAC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
进一步的研究发现这个关于此问题的论坛主题,其中有人建议这可能是由于 VS2008 的性能分析功能保留了旧版本的程序集造成的。
我能够通过以下方式解决我的问题:
我不确定是哪一个这些步骤显然是必要的,但这种“厨房水槽”方法为我解决了这个问题。
更新:这篇 Microsoft 文章指出,当编译解决方案后,即使“复制本地”设置为 true,GAC 中找到的程序集也永远不会复制到输出 bin\ 文件夹中。
Further research turned up this forum thread on this issue, in which someone suggests this might be caused by VS2008's Performance Analysis feature holding onto a stale version of the assembly.
I was able to solve my problem by:
I'm not sure which of these steps were explicitly necessary, but this "kitchen sink" approach resolved the issue for me.
Update: This Microsoft article states that when a solution is compiled, assemblies found in the GAC are never copied to the output bin\ folder, even if "Copy Local" is set to true.
就我而言,我有两个相同(几乎)的程序集,但位置不同。
测试项目引用第一个程序集,UnitTest 项目引用第二个程序集(它们完全相同)。
因此,请仔细检查所有项目参考资料。
In my case I had two the same (almost) assemblies with different locations.
The tested project was referenced to the first assembly and the UnitTest project was referenced to the second one (they were absolutely the same).
So check carefully all of the project references.