-
Notifications
You must be signed in to change notification settings - Fork 209
NativeAot web core api custom error return code error System.Reflection.MissingMetadataException #2037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The best way to deal with this error is to switch to Json source generators for your Mvc types: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation?pivots=dotnet-7-0#source-generation-support-in-aspnet-core |
@jkotas I don't know how to read this document, there is too much information in it, can you combine the case, that is, my current error, to illustrate what code I should write to solve this error? |
This error came from inside the core web api, not from my own json entity class, so I have no idea how to write this code |
builder.Services.AddControllers().
AddJsonOptions(options => options.JsonSerializerOptions.AddContext<MyJsonContext>()). // Snippet from the documentation here
ConfigureApiBehaviorOptions(setupAction => setupAction.InvalidModelStateResponseFactory = context =>
...
// Change this to use concrete type
return new Microsoft.AspNetCore.Mvc.JsonResult(new MyResult(-1, StatusCodes.Status200OK, msg = sb.ToString()));
});
...
// Definition of the concrete type
record MyResult(int code, int Status, string msg);
// Snippet from the documentation
[JsonSerializable(typeof(MyResult))]
internal partial class MyJsonContext : JsonSerializerContext { } |
thank you,is work My error probably comes from the fact that I defined a field instead of an attribute, so I return {} |
It seems to work without defining MyJsonContext, thank you. My problem is that the class field should be changed to the attribute {get; set} |
my code
How should I write the code to solve this error? I don't know anything about rd.xml syntax. I think rd.xml syntax is very complicated.
The text was updated successfully, but these errors were encountered: