-
Notifications
You must be signed in to change notification settings - Fork 10.3k
ASP.NET Core Web API (Native AOT) project fail to serialize the object to JSON #59659
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
|
Also note that MVC does not support native AOT. |
Thank you. |
Hello, I have an api project and I tried this approach and the approach with services.AddControllers().AddJsonOptions(...) as well. Both don't work. This is my code: Program.cs // Add services to the container. builder.Services.AddControllers().AddJsonOptions( // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle var app = builder.Build(); // Configure the HTTP request pipeline. app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); WeatherForcast.cs `using System.Text.Json.Serialization; namespace webApi
} [JsonSourceGenerationOptions( controller `using Microsoft.AspNetCore.Mvc; namespace webApi.Controllers
} progect file ` net8.0 enable enable false `output Still camel case, but I want snake case. |
Is there an existing issue for this?
Describe the bug
Environment:
Visual Studio Community 2022 17.12.3
Win10 + .NET SDK 8
I created an ASP.NET Core Web API (Native AOT) project in Visual Studio using .NET 8. The minimal API endpoints below worked as expected:
After moving the endpoints to
TodosController.cs
and configuring the JSON serializer in a separate fileJsonTypeMetaData.cs
, I encountered the following exception:TodosController.cs
:JsonTypeMetaData.cs
:Program.cs
:WebApplication.csproj
I tried a similar solution (#59128), but it didn't work for me. Any help would be greatly appreciated.
Expected Behavior
No response
Steps To Reproduce
The mini project:
WebApplication1.zip
Exceptions (if any)
No response
.NET Version
dotnet 8.0.404
Anything else?
No response
The text was updated successfully, but these errors were encountered: