简体   繁体   English

无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Common”或其依赖项之一

[英]Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common' or one of its dependencies

I have searched google for this and could not find the solution to the problem.我已经在谷歌上搜索了这个,但找不到问题的解决方案。

My Website references DAL (custom dll) which references Enterprise Library Data Access Components.我的网站引用 DAL(自定义 dll),后者引用企业库数据访问组件。

I have added the Enterprise Library from the NuGet Package Manager and when I try to build the Website this compilation error pops up:我已经从NuGet Package Manager添加了企业库,当我尝试构建网站时弹出此编译错误:

Error 44 Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common' or one of its dependencies.错误 44 无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Common”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference找到的程序集的清单定义与程序集引用不匹配

I have tried setting the Copy Local = True in the DAL for the Enterprise Library dlls and the dlls are transferred to the Bin directory of the website along with DAL dll , but still the error pops up.我已经尝试在Enterprise Library dlls的 DAL 中设置Copy Local = True并且 dll 与DAL dll一起传输到网站的 Bin 目录,但仍然弹出错误。

Can anyone guide me on this....任何人都可以在这方面指导我......

The problem is that the DLL that you are using and the one that is referenced in your project are different. 问题是您正在使用的DLL和项目中引用的DLL是不同的。 I'm not sure what the difference in the manifest is, but it could be version and/or public key. 我不确定清单中的差异是什么,但它可能是版本和/或公钥。

You have a couple of things to try: 你有几件事要尝试:

  1. Open the properties for the DLL reference in your project and set Version Specific to false. 在项目中打开DLL引用的属性,并将Version Specific设置为false。

  2. Remove the reference, delete the DLL from the bin folder, and re-add the reference. 删除引用,从bin文件夹中删除DLL,然后重新添加引用。

  3. You could also have a different/incorrect version in your GAC. 您的GAC中也可能有不同/不正确的版本。 In order to make sure that you are always using a specific, known version create an assemblies folder relative to your project directory, copy the dll to that directory, and add a reference to the DLL in the assemblies directory rather than one in GAC or elsewhere on your machine. 为了确保您始终使用特定的已知版本创建相对于项目目录的程序集文件夹,将dll复制到该目录,并在程序集目录中添加对DLL的引用,而不是在GAC或其他地方添加在你的机器上。 This will ensure that only the specific version that you have targeted for the application will be used rather than any version that is updated on your machine at a later time. 这将确保仅使用您为应用程序定位的特定版本,而不是稍后在您的计算机上更新的任何版本。

NuGet CommonServiceLocator

Install-Package CommonServiceLocator

This dll is likely to be in the GAC on developer machines as part of some windows application installation (my best guesses are Visual Studio or SSMS). 作为某些Windows应用程序安装的一部分,这个dll可能在开发人员机器上的GAC中(我最好的猜测是Visual Studio或SSMS)。 That's why we are likely to get warnings or errors on the build machine which we try our best to keep the GAC as clean as the production server's. 这就是为什么我们可能会在构建机器上收到警告或错误,我们会尽力保持GAC像生产服务器一样干净。

To download the file manually, you can go to https://servicelocation.codeplex.com/ 要手动下载文件,您可以访问https://servicelocation.codeplex.com/

To fix the build warnings and errors, you simply need to run a NuGet command to install the CommonServiceLocation package . 要修复构建警告和错误,只需运行NuGet命令即可安装CommonServiceLocation包 The package contains only this one dll file. 该程序包仅包含此一个dll文件。 Microsoft has released only 1 version (1.0.0.0) of this file since 2008. The file is fully compatible with all .NET versions and all Unity versions. 自2008年以来,Microsoft仅发布了此文件的1个版本(1.0.0.0)。该文件与所有.NET版本和所有Unity版本完全兼容。

为Web.Config中的每个EnterpriseLibrary引用设置PublicKeyToken值为我修复了它。

I was able to resolve this issue by removing from ALL the Logging references in the app.config file:: 我能够通过删除app.config文件中的所有日志记录引用来解决此问题::

, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null

ie: 即:

    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, 
Microsoft.Practices.EnterpriseLibrary.Logging, 
Version=6.0.0.0, Culture=neutral, PublicKeyToken=null" 
requirePermission="true" />

Becomes: 变为:

     <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, 
Microsoft.Practices.EnterpriseLibrary.Logging" 
requirePermission="true" />

This is not ideal, but it does work... 这不是理想的,但确实有效......

The Enterprise Library Configuration Tool, sets the values back, so you need to watch for that. 企业库配置工具将值设置回来,因此您需要注意这一点。 I know there is a way to tell the config file to accept these mis-matched settings -- but II am not sure how. 我知道有一种方法可以告诉配置文件接受这些不匹配的设置 - 但我不知道如何。

Remove the reference, delete the DLL from the bin folder and VS, and re-add the reference.去掉引用,从bin文件夹和VS中删除DLL,重新添加引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在WCF中加载文件或程序集&#39;Microsoft.Practices.EnterpriseLibrary.Common - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common in WCF 无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Common,Version=6.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或 - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or 无法解决此参考。 无法找到程序集“ Microsoft.Practices.EnterpriseLibrary.Common” - Could not resolve this reference. Could not locate the assembly “Microsoft.Practices.EnterpriseLibrary.Common” 无法加载文件或程序集Microsoft.Practices.EnterpriseLibrary.Configuration - Could not load file or assembly Microsoft.Practices.EnterpriseLibrary.Configuration “无法加载文件或程序集&#39;Microsoft.Practices.EnterpriseLibrary.Validation”异常 - “Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Validation” exception 无法加载文件或程序集&#39;Microsoft.Practices.EnterpriseLibrary.Logging - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging 无法加载文件或程序集&#39;Microsoft.Practices.EnterpriseLibrary.Caching - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Caching &#39;您必须添加对Microsoft.Practices.EnterpriseLibrary.Common的引用&#39;,即使汇编在GAC中 - 'You must add a reference to Microsoft.Practices.EnterpriseLibrary.Common' even though assembly is in the GAC Microsoft.Practices.EnterpriseLibrary.Common在IIS 8.5中不起作用,但它在IIS 7.0中工作 - Microsoft.Practices.EnterpriseLibrary.Common is not working in IIS 8.5 but its working in IIS 7.0 无法加载文件或程序集“ Microsoft.ReportViewer.Common”或其依赖项之一。 -正在使用文件 - Could not load file or assembly 'Microsoft.ReportViewer.Common' or one of its dependencies. - File is being used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM