在MVC中使用dotnet核心时如何删除ErrorViewModel [英] How to remove ErrorViewModel when using dotnet core with MVC

查看:50
本文介绍了在MVC中使用dotnet核心时如何删除ErrorViewModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果从我的项目中删除了ErrorViewModel,它将无法运行,并在 app.UseMvc()上失败,并显示错误:

If ErrorViewModel is removed from my project, it won't run, failing at app.UseMvc() with the error:

System.TypeLoadException:'无法加载类型程序集'DocumentGenerationService,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'中的'DocumentGenerationService.Models.ErrorViewModel'.

System.TypeLoadException: 'Could not load type 'DocumentGenerationService.Models.ErrorViewModel' from assembly 'DocumentGenerationService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.'

这是一个带有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:

  1. 删除所有与ErrorViewModel相关的文件,例如Controllers,Views ...
  2. 关闭Visual Studio(如果已打开)
  3. 转到源目录并删除 obj bin 目录
  4. 使用Visual Studio打开项目并运行它

现在它应该可以作为普通的WebApi项目工作.

Now it should work as a normal WebApi project.

这篇关于在MVC中使用dotnet核心时如何删除ErrorViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆