重命名ASP.NET MVC项目时出错

Zap*_*ica 75 asp.net-mvc asp.net-authentication owin asp.net-mvc-5

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

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.
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

Fer*_*eci 167

我已经有过几次这个问题了,所以我会写下我遵循的程序,以提醒自己:

  1. 将所有旧解决方案名称替换为新解决方案名称.
  2. 导航到每个项目下的Properties,并将Assembly NameDefault Namespace字段更改为新的解决方案名称.
  3. 转到解决方案文件夹,并使用新的解决方案名称重命名所有项目文件夹.
  4. 删除binobj文件夹下的所有文件.
  5. 解决方案将无法加载项目.删除所有项目并再次添加.
  6. 重建项目.

  • 谢谢.删除"bin"文件夹的内容就是我所需要的. (85认同)
  • 如果您的网站托管在Azure上,则需要清理发布以在线删除bin和obj文件夹下的文件:http://stackoverflow.com/questions/17476525/clean-windows-azure-website (7认同)
  • 我删除了引用原始项目和Boom的特定DLL!回到工作.谢谢! (2认同)

Mil*_*hev 30

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

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


Yao*_*hen 12

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

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

接下来是删除bin文件夹中的旧程序集.


aoa*_*son 8

我没有重命名我的解决方案,但我遇到了这个问题.我无法在任何地方找到解决方案.我在同一台服务器上有一个owin启动类的2个独立项目.我只是给每个人一个不同的"友好名称",如异常消息中所建议的,它解决了它.我发现了一篇很好的文章:

Owin Startup Class

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

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