question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MigrationsEndPoint throwing `InvalidOperationException: Incorrect Content-Type:` on load

See original GitHub issue

Is 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?

image

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
Tratchercommented, Feb 15, 2023

Run the project and go to …/ApplyDatabaseMigrations page

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-L55

We’d either produce a more specific error, log, or no-op.

1reaction
adityamandaleekacommented, Mar 20, 2023

I think this is left open to address the last part of @Tratcher’s comment (improving what we do when this condition is hit).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found