问题描述
如果从我的项目中删除了ErrorViewModel,它将无法运行,并在 app.UseMvc()
上失败,并显示错误:
If ErrorViewModel is removed from my project, it won't run, failing at app.UseMvc()
with the error:
这是一个带有mvc的dotnet核心2.2应用程序.我已经删除了应用程序不必要的所有内容,其中包括所有视图,因为这是一个webapi项目.
It is a dotnet core 2.2 application with mvc. I've removed everything that is unnecessary to the application, which includes all the views, as this is a webapi project.
为什么不能从项目中删除ErrorViewModel?这让我很难过.
Why can't I remove ErrorViewModel from the project? It's making me sad.
作为参考,下面是启动类的外观:
For reference, here's how the startup class looks:
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddSignalR();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseMvc();
}
}
有什么想法如何摆脱ErrorViewModel类并使项目运行?或解释为何无法实现?
Any ideas how to get rid of the ErrorViewModel class and have the project run? Or an explanation of why it isn't possible?
感谢StackOverflowers!
Thanks StackOverflowers!
推荐答案
我遇到了同样的问题,以下解决方案对我有效:
I had the same problem and the following solution worked for me:
- 删除所有与ErrorViewModel相关的文件,例如Controllers,Views ...
- 关闭Visual Studio(如果已打开)
- 转到源目录并删除
obj
和bin
目录 - 使用Visual Studio打开项目并运行它
现在它应该可以作为普通的WebApi项目工作.
Now it should work as a normal WebApi project.
这篇关于在MVC中使用dotnet核心时如何删除ErrorViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!