MigrationsEndPoint throwing `InvalidOperationException: Incorrect Content-Type:` on load
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
package installed and I use app.UseMigrationsEndPoint()
on my Program.cs
. Whenever I enter migrations url (/ApplyDatabaseMigrations) I get this exception:
Seems like its missing Content-Type application/x-www-form-urlencoded
in Headers.
Expected Behavior
It should load the migrations page correctly and include application/x-www-form-urlencoded
Content-Type header.
Steps To Reproduce
Run the project and go to .../ApplyDatabaseMigrations
page
https://github.com/Hantick/EntityFrameworkCoreBug
Exceptions (if any)
System.InvalidOperationException: Incorrect Content-Type:
at Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.GetDbContext(HttpContext context, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.InvokeCore(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
.NET Version
7.0.100
Anything else?
Issue Analytics
- State:
- Created 9 months ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
Incorrect Content-Type: Microsoft.AspNetCore.Http. ...
I am new to Asp.net MVC Core. I am working on Server-side loading of JQuery Datatables.net using Asp.Net Core MVC Middleware. I have...
Read more >Handle errors in ASP.NET Core web APIs
A problem details response is generated with the previous code when any of the following conditions apply: An invalid input is supplied. The...
Read more >Unable to resolve service for type in .NET 5 with entity ...
InvalidOperationException : Unable to resolve service for type 'EC.DataAccess.EF.Context.ECContext' while attempting to activate 'EC09.
Read more >Unable to resolve service for type while attempting ...
EntityFrameworkCore.DatabaseDeveloperPageExceptionFilter: Error: An exception occurred while calculating the database error page content.
Read more >Client Found Response Content Type Of 'text/html; Charset ...
System.InvalidOperationException: Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’re not supposed to navigate directly to the ApplyDatabaseMigrations page (GET), you’re supposed to click the ApplyMigrations button on the error page that submits a Form POST to that path with the necessary details.
https://github.com/dotnet/aspnetcore/blob/cf342f8ea5e642fa533bda30195d2666c51fad30/src/Middleware/Diagnostics.EntityFrameworkCore/src/Views/DatabaseErrorPage.cshtml#L90 https://github.com/dotnet/aspnetcore/blob/cf342f8ea5e642fa533bda30195d2666c51fad30/src/Middleware/Diagnostics.EntityFrameworkCore/src/Views/DatabaseErrorPage.cshtml#L117-L120
We could make this clearer by adding a check for POST and
Content-Type: application/x-www-form-urlencoded
here: https://github.com/dotnet/aspnetcore/blob/cf342f8ea5e642fa533bda30195d2666c51fad30/src/Middleware/Diagnostics.EntityFrameworkCore/src/MigrationsEndPointMiddleware.cs#L53-L55We’d either produce a more specific error, log, or no-op.
I think this is left open to address the last part of @Tratcher’s comment (improving what we do when this condition is hit).