.Net Core 8 Json Serialization error
Using Json Serializer on a class, I experienced the following error :
Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at MyApp.Cred.Serialize() in C:\WorkSpace\MyApp\MyApp\Cred.cs:line 16
at MyApp.Config.SetConfig() in C:\WorkSpace\MyApp\MyApp\Config.cs:line 58
at MyApp.Config.Do() in C:\WorkSpace\MyApp\MyApp\Config.cs:line 44
at MyApp.Program.Main(String[] args) in C:\WorkSpace\MyApp\MyApp\Program.cs:line 35
Fix is simple but tricky. Edit the csproj file and add the following line :
|
|