asp.net-mvc 重命名 ASP.NET MVC 项目时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21701297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:32:11  来源:igfitidea点击:

Error renaming ASP.NET MVC project

asp.net-mvcasp.net-mvc-5owinasp.net-authentication

提问by Zapnologica

I have copied a previous project and renamed it. Once I had successfully renamed all the name spaces and it build correctly. I got the following error when I ran the application:

我复制了一个以前的项目并重命名了它。一旦我成功地重命名了所有的命名空间并且它构建正确。运行应用程序时出现以下错误:

The following errors occurred while attempting to load the app.
- The OwinStartup attribute discovered in assembly 'User Manager Interface' referencing    startup type 'User_Manager_Interface.Startup' conflicts with the attribute in assembly   'Service Monitor Web Interface' referencing startup type  'Service_Monitor_Web_Interface.Startup' because they have the same FriendlyName ''. Remove or   rename one of the attributes, or reference the desired type directly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

I have figured out that if I comment out the first line below then the error goes away.

我发现如果我注释掉下面的第一行,那么错误就会消失。

//[assembly: OwinStartupAttribute(typeof(Service_Monitor_Web_Interface.Startup))]
namespace Service_Monitor_Web_Interface
{
public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
    }
}
}

I renamed my solution from User_Manager_Interface to Service_Monitor_Web_Interface.

我将我的解决方案从 User_Manager_Interface 重命名为 Service_Monitor_Web_Interface。

I cant seem to find any places with the old name, howevel in the error it mentions it.

我似乎无法找到任何具有旧名称的地方,但是在它提到的错误中却如此。

回答by Ferit Buyukkececi

I had this issue a few times already, so I will write down the procedure I follow also as a reminder for myself:

我已经遇到过几次这个问题,所以我会写下我遵循的程序作为对自己的提醒:

  1. Replace all of the old solution name with the new one.
  2. Navigate to Propertiesunder each project and change the Assembly Nameand Default Namespacefields to new solution name.
  3. Go to solution folder and rename all project folders with the new solution name.
  4. Remove all files under binand objfolders.
  5. Solution will not be able to load projects. Remove all projects and add them again.
  6. Re-build the project.
  1. 用新的解决方案名称替换所有旧的解决方案名称。
  2. 导航到每个项目下的属性并将程序集名称默认命名空间字段更改为新的解决方案名称。
  3. 转到解决方案文件夹并使用新的解决方案名称重命名所有项目文件夹。
  4. 删除binobj文件夹下的所有文件。
  5. 解决方案将无法加载项目。删除所有项目并再次添加它们。
  6. 重新构建项目。

回答by Milen Kovachev

This problem will occur if you have two assemblies in the same bin folder which contain an OwinStartup class. Normally you should not have two OwinStartup classes for the same web application.

如果在同一个 bin 文件夹中有两个包含 OwinStartup 类的程序集,则会出现此问题。通常,同一个 Web 应用程序不应有两个 OwinStartup 类。

You can solve this by inspecting your bin folder. If after the rename an assembly with the old name has remained in the bin folder you will get this error. To solve it delete everything from the bin folder.

您可以通过检查 bin 文件夹来解决此问题。如果重命名后具有旧名称的程序集仍保留在 bin 文件夹中,您将收到此错误。要解决它,请从 bin 文件夹中删除所有内容。

回答by Yaobin Then

I was having the same problem after renaming the assembly of the solution.

重命名解决方案的程序集后,我遇到了同样的问题。

I solved by making sure the OwinStartupAttritbute is refering to my new assembly name.

我通过确保 OwinStartupAttritbute 引用我的新程序集名称来解决。

Next is to delete the old assembly found in bin folder.

接下来是删除在 bin 文件夹中找到的旧程序集。

回答by aoakeson

I did not rename my solution, but I did run into this problem. I couldnt find a solution posted anywhere about this. I had 2 separate projects with an owin startup class on the same server. I simply gave each one a different "Friendly Name" as suggested in the exception message, and it solved it. I found a good article on this:

我没有重命名我的解决方案,但我确实遇到了这个问题。我找不到任何有关此问题的解决方案。我有 2 个单独的项目,在同一台服务器上有一个 owin 启动类。我只是按照异常消息中的建议给每个人一个不同的“友好名称”,它解决了这个问题。我找到了一篇关于这个的好文章:

Owin Startup Class

欧文创业班

To rename it, all you need to do is add a string on the OwinStartup Like so:

要重命名它,您需要做的就是在 OwinStartup 上添加一个字符串,如下所示:

[assembly: OwinStartup("ProductionConfiguration", typeof(StartupDemo.ProductionStartup2))]

[程序集:OwinStartup("ProductionConfiguration", typeof(StartupDemo.ProductionStartup2))]

回答by Amit Jaiswal

Add following tag on web config appsetting

在 web config appsetting 上添加以下标签

<appSettings>
   <add key="owin:AutomaticAppStartup" value="false" />   
</appSettings>

回答by Chun Lin

I have two ASP .NET MVC 5 projects, Project1 and Project2.

我有两个 ASP .NET MVC 5 项目,Project1 和 Project2。

The problem is that the the DLL of two the projects are in the same bin folder and both are using Owin middleware. This means Project1.dll and Project2.dll exist in the same bin folder of the Project2.

问题是两个项目的 DLL 都在同一个 bin 文件夹中,并且都使用 Owin 中间件。这意味着 Project1.dll 和 Project2.dll 存在于 Project2 的同一个 bin 文件夹中。

Since I only need one of them in each of the project, so I just remove the unused Project1.dll in Project2 bin folder.

由于我在每个项目中只需要其中一个,所以我只删除了 Project2 bin 文件夹中未使用的 Project1.dll。