gpt4 book ai didi

asp.net-mvc - 尝试执行多项目 ASP.Net MVC 站点时出现编译错误

转载 作者:行者123 更新时间:2023-12-02 01:12:59 24 4
gpt4 key购买 nike

我收到此错误。

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1704: An assembly with the same simple name 'MyMVCAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.

我的解决方案有 2 个 ASP.Net MVC 项目 - 划分主要内容和区域。主项目没有引用第二个项目。相反,它获取文件夹中的所有 MVC DLL 并将其存储到 IOC 容器中,该容器负责注册所有 Controller 。

当我将第二个 ASP.Net MVC 项目的输出设置到主项目的 bin 文件夹中时,出现错误。 (我已将“区域”解决方案中的所有 View 设置为“始终复制”。)

我还尝试了将 DLL 复制到主 bin 中的构建后操作,而不是设置输出,但结果是相同的。

我应该做什么?

<小时/>

此外,我还有以下设置:

  1. 它设置为使用本地 IIS 服务器而不是 VS Dev 服务器。
  2. 在“输出”窗口中,我看到本地 Web 服务器正在从 GAC 和临时 ASP.Net 文件文件夹加载所有 DLL。我看到的问题是它还尝试从我的 Solutions 文件夹加载我的 DLL 文件。

你知道为什么它也试图从解决方案中获取唯一的 DLL 吗?其他项目没有这种行为。

<小时/>

更新:

这是一个奇怪的行为:

[1] 我清除了有问题的程序集的所有副本。

[2] 我删除了将该程序集复制到我的主 MVC 项目 bin 文件夹的构建后操作。

[3] 我运行主项目。它可以正常工作,但当然不会加载缺少的程序集。

[4] 我手动将该程序集复制到 Mian MVC 项目 bin 文件夹中。

[5] 我运行解决方案。它又出现错误了!

有人可以解释为什么它试图从两个不同的地方加载这个完全相同的程序集吗?

好吧,这可能是问题的线索:因为我将程序集复制到主 MVC 项目的 bin 文件夹中,所以它也被复制到临时 ASP.NEt 文件夹中。同时,由于该项目没有被解决方案中的任何其他项目引用,因此它还将相同的程序集复制到 IIS 中。我怎样才能防止这种情况发生?如果我排除将程序集复制到主 MVC bin 的步骤,则它根本不会加载到 IIS 中。为什么会这样?

最佳答案

This error points out that two references have the same assembly identity because the assemblies in question lack strong names, they were not signed, and thus the compiler has no way of distinguishing between them in metadata. Thus, the run time ignores the version and culture assembly name properties. The user should remove the redundant reference, rename one of the references, or provide a strong name for them.

可以像下面这样解释。

下面的示例创建一个程序集并将其保存到根目录。

// CS1704_a.cs
// compile with: /target:library /out:c:\\cs1704.dll
public class A {}

下面的示例创建一个与上一个示例同名的程序集,但将其保存到不同的位置。

// CS1704_b.cs
// compile with: /target:library /out:cs1704.dll
public class A {}

下面的示例尝试引用这两个程序集。下面的示例生成 CS1704

// CS1704_c.cs
// compile with: /target:library /r:A2=cs1704.dll /r:A1=c:\\cs1704.dll
// CS1704 expected
extern alias A1;
extern alias A2;

更新

如果两个程序集都是强命名(签名)的,则 CLR 将始终从 GAC 加载。

您可以按照以下步骤操作:

  1. Determines the correct assembly version by examining applicable configuration files, including the application configuration file, publisher policy file, and machine configuration file. If the configuration file is located on a remote machine, the runtime must locate and download the application configuration file first.

  2. Checks whether the assembly name has been bound to before and, if so, uses the previously loaded assembly. If a previous request to load the assembly failed, the request fails immediately without attempting to load the assembly.

  3. Checks the global assembly cache. If the assembly is found there, the runtime uses this assembly.

  4. Probes for the assembly (for more info check below mentioned article )

了解更多信息请查看How the Runtime Locates Assemblies

希望这对您有帮助。

关于asp.net-mvc - 尝试执行多项目 ASP.Net MVC 站点时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14301693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com