Closed kfathy-ys closed 1 year ago
Maybe is too late but you need to add this nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson and then add builder.Services.AddControllers().AddNewtonsoftJson(); in your Program.cs or Startup.cs file.
Maybe is too late but you need to add this nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson and then add builder.Services.AddControllers().AddNewtonsoftJson(); in your Program.cs or Startup.cs file.
The original comment is related to System.Text.Json
and using the above configuration for MVC and Newtonsoft.Json
won't fix this issue as far as I know.
We should be able to fix this by either providing a customer serializer for System.Text.Json or possibly refactoring the Result
class to make Type
a calculated field using an expression. I'll try to work with Steve to get a fix in for this soon.
Do we need related serializer packages like we have for Ardalis.SmartEnum?
@ardalis I would personally like serialization support for a result/array of results.
I got this issue when I used [TranslateResultToActionResult]
attribute but my controller didn't inherited ControllerBase
class.
When I added the inheritance everything worked as expected.
I believe this can be resolved by making the Type field use an expression rather than a property with an underlying field. I will try to put up a PR with the proposed changes here shortly.
When return result it get exception : System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported. Path: $.ValueType. ---> System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported. at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter
1.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) at System.Text.Json.Serialization.JsonConverter
1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter
1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter
1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)public Result AddUser(AddUserRequest addUserRequest)
{
try
{
return Result.Success("test");
}