Could not create an instance of type ‘Microsoft.AspNetCore.Http.HttpContext’

The new version of dotnet core cannot handle the HttpContext in the MVC model.

An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Could not create an instance of type ‘Microsoft.AspNetCore.Http.HttpContext’. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, set the ‘HttpContext’ property to a non-null value in the ‘…’ constructor.

Solution

Remove the line from the model:

public HttpContext HttpContext { get; set; }

Remove the line from the controller:

model.HttpContext = HttpContext;

Leave a comment

Your email address will not be published. Required fields are marked *