加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 09:38:19 所属栏目:asp.Net 来源:网络整理
导读:我收到了这个错误. 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. Compile
我收到了这个错误.

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容器中,该容器负责注册所有控制器.

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

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

我该怎么办?

另外,我有以下设置:

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

任何想法为什么它试图从解决方案中获得唯一的DLL?它没有其他项目的行为.

更新:

这是一个奇怪的行为:

[1]我清除了违规集会的所有副本.

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

[3]我运行主项目.它没有任何问题,但当然缺少装配不会被加载.

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

[5]我运行解决方案.它再次出错了!

有人可以解释为什么它试图从两个不同的地方加载这个相同的组件?

好吧,这可能是问题的线索:因为我将程序集复制到主MVC项目的bin文件夹,它也被复制到Temporary 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;

UPDATE

如果两个程序集都是强名称(签名),则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

我希望这会对你有所帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读