请求的服务“Microsoft.AspNetCore.Mvc.ViewFeatures”。尚未注册ITempDataDictionaryFactory。
.net5程序启动异常
The requested service 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
**报错是因为没有注册:ITempDataDictionaryFactory,说白了就是没有注册mvc架构**
解决方案
- 修改 Startup.cs 中的 ConfigureServices方法
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
- 修改 Startup.cs 中的 ConfigureServices方法
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}
参考
https://www.cnblogs.com/ansheng/p/14239237.html