当程序集位于 GAC 中时,Visual Studio 单元测试会抛出 MissingMethodException?

发布于 2024-07-07 10:37:16 字数 474 浏览 6 评论 0原文

我的应用程序包含一段在组件服务内部执行的代码,因此我们需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

血之狂魔 2024-07-14 10:37:16

进一步的研究发现这个关于此问题的论坛主题,其中有人建议这可能是由于 VS2008 的性能分析功能保留了旧版本的程序集造成的。

我能够通过以下方式解决我的问题:

  1. 重建我的解决方案,然后
  2. 刷新 GAC 中的所有内容,然后
  3. 删除并重新添加测试项目中的程序集引用,然后
  4. 关闭并重新打开 Visual Studio 2008

我不确定是哪一个这些步骤显然是必要的,但这种“厨房水槽”方法为我解决了这个问题。

更新:这篇 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:

  1. Rebuilding my solution, then
  2. Refreshing everything in the GAC, then
  3. Removing and re-adding the assembly references in my test project, then
  4. Closing and re-opening Visual Studio 2008

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.

转身泪倾城 2024-07-14 10:37:16

就我而言,我有两个相同(几乎)的程序集,但位置不同。
测试项目引用第一个程序集,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文