Is polymorphic deserialization possible in System.Text.Json?

Is polymorphic deserialization possible in System.Text.Json? The answer is yes and no, depending on what you mean by “possible”. There is no polymorphic deserialization (equivalent to Newtonsoft.Json’s TypeNameHandling) support built-in to System.Text.Json. This is because reading the .NET type name specified as a string within the JSON payload (such as $type metadata property) to create … Read more

System.Text.Json.JsonElement ToObject workaround

In .NET 6, extension methods are being added to JsonSerializer to deserialize an object directly from a JsonElement or JsonDocument: public static partial class JsonSerializer { public static TValue? Deserialize<TValue>(this JsonDocument document, JsonSerializerOptions? options = null); public static object? Deserialize(this JsonDocument document, Type returnType, JsonSerializerOptions? options = null); public static TValue? Deserialize<TValue>(this JsonDocument document, JsonTypeInfo<TValue> … Read more

“The project ‘Web’ must provide a value for Configuration” error after migrating to .NET Core 3

The issue turned out to be that I was still referencing Microsoft.AspNetCore.Razor.Design Version=”2.2.0″ in the .proj file’s package references. Deleting that reference (which isn’t needed at all as Razor.Design is now part of AspNetCore library) fixed the issue. Once I’d done that, I then got hundreds of errors about nullable objects being a new feature … Read more