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



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

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.

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

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

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

我似乎找不到任何带有旧名称的地方,在它提到的错误中如何。

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

    将所有
  1. 旧解决方案名称替换为新名称。
  2. 导航到每个项目下的"属性",并将"程序集名称"和"默认命名空间"字段更改为新的解决方案名称。
  3. 转到解决方案文件夹,并使用新的解决方案名称重命名所有项目文件夹。
  4. 删除 binobj 文件夹下的所有文件。
  5. 解决方案将无法加载项目。删除所有项目,然后重新添加它们。
  6. 重新生成项目。

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

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

重命名

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

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

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

我没有

重命名我的解决方案,但我确实遇到了这个问题。我找不到随处发布的解决方案。我在同一台服务器上有 2 个单独的项目和一个 owin 启动类。 我只是按照异常消息中的建议为每个对象指定了不同的"友好名称",它解决了它。 我找到了一篇关于这个的好文章:

欧文创业班

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

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

在 Web 配置应用程序设置上添加以下标签

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

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

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

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

只需清理解决方案,它应该可以解决问题;)

最新更新