Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

System.Security.VerificationException: Operation could destabilize the runtime
RobertTheGrey
#1 Posted : Tuesday, July 10, 2012 8:27:43 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/10/2012(UTC)
Posts: 6
Location: UK

Thanks: 3 times
Hi there,

I work on the OSS Spark View Engine (https://github.com/SparkViewEngine/spark), which has something like 700 tests which all pass without an issue using NUnit or the ReSharper test runner. When running NCrunch, it throws this particular exception (System.Security.VerificationException: Operation could destabilize the runtime). The particular project in question does use System.Security and in the AssemblyInfo sets the following:

[assembly: AllowPartiallyTrustedCallers]

When I remove this line, then the test passes just fine, but I cannot understand why I need to remove this for a test runner to work. In fact, this attribute is required for some edge cases of libs that call into this to work properly, and removing this would be a breaking change in the next release.

Is there another way to fix this in the NCrunch runner, or at least an explanation as to why this fails, but passes other test runners?

Thanks,
Rob



Remco
#3 Posted : Monday, August 13, 2012 4:02:45 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Rob -

I just picked up this question while skimming through forum material, and realised that it hadn't been answered. I'm not sure how it slipped through my net, and I'm sorry it's taken so long to get back to you.

NCrunch uses a different security setup within its application domain to other test runners. I've yet to establish exactly why this setup is different or how to change it, though I have an item on my list to look into it in more detail. Thanks for making me aware of the problem.


Cheers,

Remco
0liver
#4 Posted : Friday, August 31, 2012 9:18:17 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/31/2012(UTC)
Posts: 5
Location: Poland

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Hello,

I've finally set up NCrunch for a larger Orchard CMS solution, and I'm getting the "System.Security.VerificationException : Operation could destabilize the runtime" as well for code that originates from a couple of assemblies which declare [assembly: SecurityTransparent].

Is there any chance to get this to work soon, maybe using some dirty hack, e.g. globally disabling all Security related attributes or the like? I really start to like NCrunch for the much faster feedback cycle when writing tests but this is a show stopper right now, at least for the given project.

Please advise.

Cheers, Oliver
Remco
#5 Posted : Friday, August 31, 2012 11:01:30 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Oliver,

Right now NCrunch simply doesn't support working with partially trusted code (or code access security), as this adds a considerably complex dimension to its development and may not actually be possible with the way it works internally (more testing is required). I'd like to introduce an override to force it to deactivate security, although this is all still a work in progress and I can't yet promise when I'll have a fix available.

Meanwhile, I strongly suggest you switch off and avoid using code access security for code that is under test by NCrunch. The easiest way to do this is by using a compiler directive to turn off the CAS attributes when the projects are being built/processed by NCrunch. NCrunch sets a compiler conditional 'NCRUNCH' for specifically this purpose:

#if !NCRUNCH
[assembly: SecurityTransparent]
#endif

.. this should (in theory) solve the problem for your NCrunch test environment.


Cheers,

Remco
1 user thanked Remco for this useful post.
0liver on 9/1/2012(UTC)
0liver
#6 Posted : Monday, September 3, 2012 10:49:46 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/31/2012(UTC)
Posts: 5
Location: Poland

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Hi Remco,

thanks again for your answer. The workaround you posted was pretty much exactly what I was thinking of: quick'n'dirty but works. Now all our tests run just fine :-)

Cheers,
Oliver
1 user thanked 0liver for this useful post.
Remco on 9/3/2012(UTC)
Remco
#7 Posted : Sunday, October 7, 2012 11:28:49 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
For anyone else that experiences the above issue, I've done a bit more digging to try and get to the core of why NCrunch is behaving differently to other test runners in this situation.

Because of the need to support pre-v4 versions of the .NET framework, NCrunch makes use of .NET framework 2.0 assemblies in some of the code it inserts for instrumentation. In v4 of the .NET framework, Microsoft introduced major changes to the security model that aren't seamlessly backwards compatible with the old CAS approach. This means that inside the NCrunch test environment, .NET v4 and above code may experience security related issues when attempting to impose constraints (or remove constraints!) using assembly-level attributes.

There is a useful article that goes through the motions of troubleshooting an identical issue encountered with Visual Studio MSTest's built-in code coverage.

Any solution to this issue from the side of NCrunch will require some re-engineering and looks like it will still be a long way out. If you encounter this problem, I recommend either using the compiler conditional shown above to deactivate the assembly-level security attributes for NCrunch builds, or to introduce the following attribute (perhaps with an NCrunch compiler conditional around it if you want to be certain of normal behaviour outside the NCrunch environment):

[assembly: SecurityRules(SecurityRuleSet.Level1)]

I hope someone finds this useful.


Cheers,

Remco
Atreyu
#8 Posted : Wednesday, May 8, 2013 8:57:54 AM(UTC)
Rank: Member

Groups: Registered
Joined: 1/11/2013(UTC)
Posts: 11
Location: Netherlands

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
I would like to use the compiler-constant-hack, but unfortunately my project is VB, which does not seem to have the NCRUNCH compiler constant set. (as explicitly stated in: http://www.ncrunch.net/d...unch-specific-overrides)
Is there any way I could achive the same effect in VB?
Remco
#9 Posted : Wednesday, May 8, 2013 10:20:21 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Atreyu,

Thanks for posting!

The easiest way to handle this is to simply alter the VB project's .vbproj file and make use of NCrunch's conditional compilation. Inside the default/debug configuration property group, add the following line:

<DefineConstants Condition="$(NCRUNCH) == '1'">NCRUNCH</DefineConstants>

If you already have an existing 'DefineConstants' in the file, you may need to do something like this:

<DefineConstants Condition="$(NCRUNCH) == '1'">MYEXISTINGCONSTANT,NCRUNCH</DefineConstants>
<DefineConstants Condition="$(NCRUNCH) == ''">MYEXISTINGCONSTANT</DefineConstants>

I hope this does the trick.


Cheers,

Remco
dylanbeattie
#10 Posted : Wednesday, August 28, 2013 9:58:39 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/20/2012(UTC)
Posts: 12
Location: London

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
Hi,

I'm having the same problem ("System.Security.VerificationException : Operation could destabilize the runtime.")

My project is building DotNetOpenAuth and ServiceStack from source, and using VS project references to include these projects in my own app and tests.

I've been through all the code - both my own code and the libraries I'm including - and replaced

[assembly: AllowPartiallyTrustedCallers]

with

#if !NCRUNCH
[assembly: AllowPartiallyTrustedCallers]
#endif

but this hasn't worked - still get a VerificationException trying to run tests in NCrunch. What else should I try?

Thanks,

Dylan
Remco
#12 Posted : Wednesday, August 28, 2013 10:41:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Dylan -

Can you confirm whether you're using the latest version of NCrunch? I vaguely remember there being a recent fix for several situations that can cause this issue..

Something else to look for - do you have any other security related attributes defined in the project you're experiencing this problem in?


Cheers,

Remco
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.083 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download