views:

36

answers:

2

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?

A: 

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.

Philip Rieck
Running under 4.0 (not Client profile) does not fix the issue. Also, all the code is available for download in the link in the question.
Dave Van den Eynde
+1  A: 

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.

Darin Dimitrov
Good call! I'll check in a minute to see what's changed in Code Coverage for VS2010.
Dave Van den Eynde