Why do my tests fail with System.Security.VerificationException?

I am migrating one of my projects from VS2008 to VS2010. Now that I have converted all my projects to a .NET 4.0 solution (client profile), when I run a test bundle, almost all tests fail with the following exception:

System.Security.VerificationException: Operation may destabilize at runtime.

I was unable to determine why this exception occurs. Tests run fine when I run them in debug mode.

The whole solution is available for download here .

Can someone point me in the right direction?

+3
source share
3 answers

The problem seems to be related to the activation of the coverage code. Refusing code coverage solves the problem. You can put the following in your AssemblyInfo.cs:

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

and activate code coverage.

+3
source

First step: run the peverify tool against built-in assemblies (both test and application). This may give you some results that help identify the problem.

Second step: can you give us a stack trace or an exception output? Once I really saw an error with this in .net 2 and was a compiler error - I had to slightly modify the code in order to compile the call as a virtual rather than a direct call. Providing us with the stack and lines of code in question would be helpful.

One thing that I want to note is that applications running under client profile 4.0 have different security rules than running under 3.5. You can try adding [assembly: SecurityRules(SecurityRuleSet.Level1)] to your assemblyinfo.cs to run in accordance with the "old style" rules to reduce it.

+1
source

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

Our projects already focused on .NET 4.0 and unit tests worked before the update.

Since .Net 4.5 is an in-place upgrade, the 4.0.Net 4.5 bug introduced by Microsoft may cause this problem in targeted .Net 4.0 projects. This is probably due to the SecurityRules answer, but internal to dll systems (e.g. Microsoft.VisualStudio.QualityTools.UnitTestFramework).

For the fix related below, the following was fixed: "The operation may destabilize the execution time." exceptions to what was otherwise working unit tests.

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

Hope this saves someone else time

0
source

Source: https://habr.com/ru/post/893688/


All Articles