0

Recently in one of the Web Applications, we started getting VerificationException while trying to serialize an object using JSON.NET.

I understand that JSON.NET enables CLR verification because it uses [assembly: AllowPartiallyTrustedCallers] ,but all below code samples throw same exception

1) JsonConvert.SerializeObject(log);

2) var settings = new Newtonsoft.Json.JsonSerializerSettings
        {
            Formatting = Newtonsoft.Json.Formatting.Indented
        };

3) var traceWriter = new MemoryTraceWriter();

It happens on specific machine (A) and not on the other (B), below what I did to isolate the problem:-

  1. Execute Code A on machine B works not vice versa.
  2. Compared installed .NET versions between A and B.
  3. Compared installed features,roles, IIS settings between the two machines.
  4. Implemented a small console which uses JSON.NET and it worked normally on machine A.
  5. Used PEverify and SecAnnotation and everything seems fine.
  6. Did a clean installation of Frameworks with no success.
  7. Tried installing couple of .NET KBs.

.NET 4.7.1

JSON.NET 10.0.3

IIS 7.5

Windows Server 2008 R2

Edit 1 ToString Output

System.Security.VerificationException: Operation could destabilize the runtime.
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value)

Edit 2 Call stack from DebugDiag

    KERNELBASE!RaiseException+3d 
MSVCR120_CLR0400!CxxThrowException+c3 
clr!NGenCreateNGenWorker+d33c 
clr!TranslateSecurityAttributes+82981 
[[HelperMethodFrame]] 
Newtonsoft.Json.JsonConvert.SerializeObject(System.Object)+15 

What might be the reason of the exception?

2
  • There was a change to MemoeyTraceWriter in release 10.0.3: Fix - Fixed MemoryTraceWriter thread safety. What happens if you 1) Revert to 10.0.2? 2) Remove use of MemoryTraceWriter? Also, can you share the full ToString() output of the exception including the exception type, message, traceback and inner exception?
    – dbc
    Mar 15, 2018 at 19:36
  • It's not related to JSON.NET as the WebApp works on environment B and WebApp from Server B throw same problem on Server A. Regarding the code samples, I am just saying that application crashes immediately when hitting of any of the lines consuming JSON.NET. I edited the question with ToString Output! Mar 16, 2018 at 8:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.