RedGate Performance Profiler / JSON.NET / Operation could destabilize the runtime

Apr 30, 2012 at 6:34 PM
Edited Apr 30, 2012 at 6:46 PM

I'm attempting to run our Silverlight application through RedGate's Performance Profiler v 7.  We're using the .NET 4.0 4.0.8.0 version of JSON.NET and I've also tried with the latest .NET 4.5 4.5.0.0 version of JSON.NET and I'm getting the same error.  When our application calls the Newtonsoft.Json.JsonConvert.SerializeObject(Object value) method, .NET is throwing the error "VerificationException: Operation could destabilize the runtime".  I did read a StackOverflow link that says you fixed the same error in the 4.0.6.0 version of JSON.NET (http://stackoverflow.com/questions/5968084/json-net-verificationexception-operation-could-destabilize-the-runtime).

I've also read that AllowPartiallyTrustedCallersAttribute changed from .NET 3.5 and .NET 4.0 which could cause this exception as well.

Running it normally through IIS works fine.  It's just when I attempt to run this through the Performance Profiler that it has an issue.


Any ideas?

Stacktrace:
[VerificationException: Operation could destabilize the runtime.]
   Newtonsoft.Json.JsonConvert.SerializeObject(Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:539
   Orion.Utility.JsonSerializerWrapper.ConvertMessageToJson(TMessage message) in c:\Code\Orion\Source\Framework\Core\Orion.Utility\JsonSerializerWrapper.cs:24

Apr 30, 2012 at 6:52 PM

Hmm.  Nevermind.  It looks like it may have been a version discrepancy in the application bin folder.

Oct 16, 2012 at 5:08 AM

Hi, I'm using version 4.5.0.0 and i have this problem... how can i solve it?

Coordinator
Oct 22, 2012 at 9:02 AM

Tell RedGate their profiler is rewriting bad IL.

Feb 28, 2013 at 3:24 PM
Edited Feb 28, 2013 at 3:25 PM
Hi, I'm the Project Manager of ANTS Performance Profiler at Red Gate. We're aware of this issue, which is due to a couple of security attributes in JSON.NET that are incompatible with line-level timings in ANTS Performance Profiler.

You can use method-level timings without a problem, but if you need line-level timings, you will need to change the JSON.NET code to remove the relevant security attributes:
1) Find JsonWriter.cs
2) Comment out "[assembly:System.Security.SecurityTransparent]"
3) Expand the Properties folder
4) In the #if !SILVERLIGHT region, comment out "[assembly:AllowPartiallyTrustedCallers]"
5) Rebuild your solution