Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
737 views
in Technique[技术] by (71.8m points)

c# - System.TypeInitializationException 'The type initializer for 'System.Text.Json.JsonSerializer' threw an exception.'

I am using System.Text.Json to write my list of objects to json file. Getting below exception while calling JsonSerializer.Serialize

System.TypeInitializationException: 'The type initializer for 'System.Text.Json.JsonSerializer' threw an exception.'

Inner exception:

  1. TypeInitializationException: The type initializer for 'System.MemoryExtensions' threw an exception.
  1. FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Any clue will be appreciated.

Solution: I was targeting lower version of .net 4.6.2 which was the reason for the crash. I upgraded to 4.8 and crash didn't happen.

question from:https://stackoverflow.com/questions/65845352/system-typeinitializationexception-the-type-initializer-for-system-text-json-j

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...