为什么我的测试失败并出现 System.Security.VerificationException?

发布于 2024-09-27 19:24:04 字数 373 浏览 2 评论 0原文

我正在将我的一个项目从 VS2008 迁移到 VS2010。现在,当我运行测试工具时,我将解决方案中的所有项目都转换为 .NET 4.0(客户端配置文件),几乎所有测试都会失败,但出现以下异常:

系统安全性验证异常: 操作可能会破坏稳定 运行时。

我一直无法确定为什么会出现此异常。当我在调试模式下运行测试时,测试运行得很好。

整个解决方案可在此处下载。

有人能指出我正确的方向吗?

I'm in the process of migrating one of my projects from VS2008 to VS2010. Now that I converted all of my projects in the solution to .NET 4.0 (Client Profile) when I run the test harness, almost all tests fail with the following exception:

System.Security.VerificationException:
Operation could destabilize the
runtime.

I've been unable to determine why this exception occurs. The tests run all fine when I run them in debug mode.

The entire solution is available for download here.

Can anyone point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

卷耳 2024-10-04 19:24:04

该问题似乎与您激活的代码覆盖率有关。禁用代码覆盖率可以解决该问题。您可以将以下内容放入 AssemblyInfo.cs:

[assembly: SecurityRules(SecurityRuleSet.Level1, SkipVerificationInFullTrust = true)]

并重新激活代码覆盖率。

The problem seems to be related to the Code Coverage you activated. Disabling code coverage solves the issue. You could put the following in your AssemblyInfo.cs:

[assembly: SecurityRules(SecurityRuleSet.Level1, SkipVerificationInFullTrust = true)]

and reactivate code coverage.

ㄟ。诗瑗 2024-10-04 19:24:04

第一步:针对构建的程序集(测试和应用程序)。它可能会为您提供一些有助于查明问题的输出。

第二步:你能给我们堆栈跟踪或异常输出吗?有一次我实际上在 .net 2 中看到了一个错误,并且是一个编译器错误 - 我必须稍微更改代码才能将调用编译为虚拟调用而不是直接调用。向我们提供有问题的堆栈和代码行会很有帮助。

我想指出的一件事是,在 4.0 客户端配置文件下运行的应用程序与在 3.5 客户端配置文件下运行的应用程序具有不同的安全行为。您可以尝试将 [assemble: SecurityRules(SecurityRuleSet.Level1)] 添加到 assemblyinfo.cs 以在“旧样式”规则下运行,以帮助缩小范围。

First step: Run the peverify tool against the built assemblies (both test and application). It may give you some output that helps pinpoint the issue.

Second step: Can you give us the stack trace or exception output? The one time I actually saw an error with this was in .net 2 and was a compiler error - I had to slightly alter the code to make a call compile as a virtual rather than direct call. Giving us the stack and the lines of code in question would be helpful.

One thing I want to point out is that apps running under the 4.0 client profile have different security behaviors than running under 3.5. You could try adding [assembly: SecurityRules(SecurityRuleSet.Level1)] to your assemblyinfo.cs to run under the "old style" rules to help narrow it down.

£噩梦荏苒 2024-10-04 19:24:04

我在从 TFS2010 升级到 TFS2012 构建服务器期间寻找非常类似问题的答案时遇到了这个问题。

我们的项目已经针对 .Net 4.0,并且单元测试在升级之前就已经开始工作。

由于 .Net 4.5 是就地升级,因此 Microsoft 引入的 .Net 4.5 错误可能会在 .Net 4.0 目标项目中导致此问题。它可能与 SecurityRules 答案相关,但在框架 dll 内部(如 Microsoft.VisualStudio.QualityTools.UnitTestFramework)。

对于我们来说,下面链接的修补程序修复了“操作可能会破坏运行时的稳定性”。工作单元测试中的例外情况。

http://support.microsoft.com/kb/2748645

我希望这可以为其他人节省很多时间

I came across this question while looking for an answer to the a very similar problem during an upgrade from a TFS2010 to TFS2012 build server.

Our projects were already targeting .Net 4.0 and unit tests were working before the upgrade.

Since .Net 4.5 is an in-place upgrade, a .Net 4.5 bug introduced by Microsoft might cause this issue in .Net 4.0 targeted projects. It is probably related to the SecurityRules answer, but internal to framework dlls (like Microsoft.VisualStudio.QualityTools.UnitTestFramework).

For us the hotfix linked below fixed the "Operation could destabilize the runtime." exceptions in what were otherwise working unit tests.

http://support.microsoft.com/kb/2748645

I hope this saves somebody else ALOT of time

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