12

I am getting the "Operation could destablize the runtime exception". I goggled quite a bit, looks like exception has to do with conflicting assemblies being loaded at runtime. So, here are couple of things

  1. the same source code works in my colleagues machine.
  2. I looked and searched for each reference to NewtonSoft.Json.dll and it seems like its coming from a same assembly. (I think this would not be a problem as it is working in other people machine).
  3. I am using Raven which references NewtonSoft, but its not being used on the server side only on the client / silverlight side. Also to be compatible I am referencing to the same version of Newtonsoft that raven is referencing to.

Now, the problem might be something I installed in the machine that's affecting this. some runtime / SP install etc. Is there a way to debug / figure out what's happening here. I looked and searched for NewtonSoft.dll when the app runs and it gets right version in the temporary asp.net files. ?

Any help could be greatly appreciated. I don't want to go through installing my runtime.

Aaron Maenpaa
  • 119,832
  • 11
  • 95
  • 108
bkhanal
  • 1,400
  • 3
  • 16
  • 24
  • That message doesn't mean that, really. I'm guessing that the library uses IL generation - that error usually means the generated IL is wrong. For example, you would get that if your stack didn't balance properly (he says from bitter experience...) – Marc Gravell May 11 '11 at 17:45
  • ya I think the library does. How would you go about debugging this? – bkhanal May 11 '11 at 17:46
  • Stack trace. Since you can get their debug symbols, see where the call to generated IL happens (mind that it could be tricky stuff, such as a property getter/setter). From there walk your way back to where the IL is generated - just keep in mind that might have happened outside of the current call chain. – em70 May 11 '11 at 18:02
  • So, I went and downloaded JSON.NET src, when I add it into the project and reference within a project, the code works, but if I go and add it as a dll reference, it fails, It seems to be failing in the class DefaultContractResolver when it tries to execute this line "return new ReflectionValueProvider(member)", It doesn't go to the constructor of the reflectionvalueprovider and just throws out an exception. Thoughts? – bkhanal May 11 '11 at 18:21
  • I built the source on my machine and it works, that doesn't answer my question though. I of course donot want to have my own version of JSON.NET that I am referencing in the code base. – bkhanal May 11 '11 at 19:53
  • possible duplicate of [Json.NET says "operation may destabilize the runtime" under .NET 4, but not under .NET 3.5](http://stackoverflow.com/questions/5511171/json-net-says-operation-may-destabilize-the-runtime-under-net-4-but-not-under) – Jehof Aug 05 '11 at 10:49

3 Answers3

20

This exception can occur when you have Visual Studio Ultimate and IntelliTrace activated.

Try to add Newtonsoft.dll on IntelliTrace ignore list:

  • Tools -> Options -> IntelliTrace -> Modules
  • Add -> Newtonsoft.
Stéphane Bebrone
  • 2,713
  • 17
  • 18
3

This bug is fixed in the latest version of Json.NET - http://james.newtonking.com/archive/2012/01/23/json-net-4-0-release-6-serialization-performance.aspx

James Newton-King
  • 48,174
  • 24
  • 109
  • 130
2

This is a known issue.

You should be able to fix this by removing all references to the JSON .NET library and adding them again to the projects.

See also:

http://json.codeplex.com/workitem/20624

JSON.Net throwing System.Security.VerificationException: Operation could destabilize the runtime

Community
  • 1
  • 1
aKzenT
  • 7,775
  • 2
  • 36
  • 65
  • I removed all reference as mentioned in the comments above and it didn't help. – bkhanal May 18 '11 at 21:19
  • Try looking at the assembly binding log (fusion log) to see what assemblys are loaded from where and to compare the versions: http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx Don't forget to set the ForceLog property in the registry like described at the end of the article to log all assembly binds and not only unsuccessful ones. – aKzenT May 24 '11 at 13:34