Unable to activate type 'Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine when starting app

Multi tool use
Unable to activate type 'Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine when starting app
Asp.net core 2.1
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
public void Configure(IApplicationBuilder app)
{
if (this.HostingEnvironment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDatabaseErrorPage();
app.UseDeveloperExceptionPage();
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller=GenericController}/{action=Get}");
});
}
Error message:
InvalidOperationException: Unable to activate type
'Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine'. The following
constructors are ambiguous: Void
.ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider,
Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator,
System.Text.Encodings.Web.HtmlEncoder,
Microsoft.Extensions.Options.IOptions1[Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions],
1[Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions],
Microsoft.AspNetCore.Razor.Language.RazorProject,
Microsoft.Extensions.Logging.ILoggerFactory,
System.Diagnostics.DiagnosticSource) Void
.ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider,
Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator,
System.Text.Encodings.Web.HtmlEncoder,
Microsoft.Extensions.Options.IOptions
Microsoft.AspNetCore.Razor.Language.RazorProjectFileSystem,
Microsoft.Extensions.Logging.ILoggerFactory,
System.Diagnostics.DiagnosticSource)
1[Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions],
Microsoft.AspNetCore.Razor.Language.RazorProject,
Microsoft.Extensions.Logging.ILoggerFactory,
System.Diagnostics.DiagnosticSource) Void
.ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider,
Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator,
System.Text.Encodings.Web.HtmlEncoder,
Microsoft.Extensions.Options.IOptions
1 Answer
1
Sounds like an issue with upgrading. I'm guessing you might have recently upgraded from 1.x?
I would try this:
Nuget packages -> Make sure your only "Web"-related installed packages are Microsoft.AspNetCore.App and Microsoft.NETCore.App. You'll probably have some CodeGeneration package as well, which shouldn't be a concern. Versions should be around 2.1.
Make sure your .csproj is cleared from everything mentioned in this migration guide: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/?view=aspnetcore-2.1
A final hail mary is clearing any weird stuff in any .config files and/or reinstalling the Nuget-packages. (And in worst case, check all your references for any non 2.1 web-related DLLs)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.