C# “无法加载文件或程序集‘Microsoft.Practices.EnterpriseLibrary.Validation”异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2001846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Validation" exception
提问by Chris
I am currently getting the following exception while trying to use the Enterprise Library Validation Application Block:
我目前在尝试使用企业库验证应用程序块时遇到以下异常:
An error occurred creating the configuration section handler for validation: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\Testers\TestProject\web.config line 12)
创建用于验证的配置节处理程序时出错:无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)(C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\Testers\TestProject\web.config line 12)
I know what the exception is trying to tell me, but I can't figure out how to fix it. I have only ever installed one version of the Enterprise Library, and this is it (4.1.0.0), so I don't see how it could be finding the wrong version, so I imagine it is then a dependency problem. I have included the "Common", "Validation" and "ObjectBuilder2" DLLs from the Enterprise Library 4.1 as references in the project, so I'm not sure what else I'm missing. The documentation certainly seems to indicate this is all I need.
我知道异常试图告诉我什么,但我不知道如何解决它。我只安装了一个版本的企业库,就是它 (4.1.0.0),所以我不知道它是如何找到错误版本的,所以我想这是一个依赖问题。我已将 Enterprise Library 4.1 中的“Common”、“Validation”和“ObjectBuilder2”DLL 作为项目引用包含在内,因此我不确定还缺少什么。文档似乎表明这就是我所需要的。
Is there any way to track down what the dependency problem is?
有没有办法追踪依赖问题是什么?
If it helps, I am trying to use the Enterprise Library Configuration Tool to create a Validation Application Block rule set for validation of data in an Entity Framework entity. I am using ASP.NET MVC in Visual Studio 2008.
如果有帮助,我正在尝试使用企业库配置工具创建验证应用程序块规则集,以验证实体框架实体中的数据。我在 Visual Studio 2008 中使用 ASP.NET MVC。
Thanks for any assistance/direction you can provide,
感谢您提供的任何帮助/指导,
Chris
克里斯
回答by dnewcome
Turn on Fusion logging and see what assembly is being bound at runtime.
打开 Fusion 日志记录并查看运行时绑定的程序集。
Hanselman had a post recently that should be helpful in enabling logging and examining the output.
Hanselman 最近发表了一篇文章,应该有助于启用日志记录和检查输出。
http://www.hanselman.com/blog/CommentView.aspx?guid=3654c8f3-c5c3-4dee-a01f-c9a8da3ef2fa
http://www.hanselman.com/blog/CommentView.aspx?guid=3654c8f3-c5c3-4dee-a01f-c9a8da3ef2fa
Another important distinction to make is that references that are added to the project are compile-time references and don't affect the way that code is bound at runtime other than to specify a strong name if a strongly named assembly was used. In order to find out what is happening at runtime you need to look at the binding logs. The log should show you all of the attempts that the runtime makes at locating the assembly. If the assembly is not in the bin directory along with your exectuable, it is most likely looking in the GAC and finding a version that it does not expect.
要做出的另一个重要区别是,添加到项目中的引用是编译时引用,并且不会影响代码在运行时绑定的方式,除非使用强命名程序集时指定强名称。为了找出运行时发生了什么,您需要查看绑定日志。该日志应显示运行时在定位程序集时所做的所有尝试。如果程序集与可执行文件不在 bin 目录中,则很可能在 GAC 中查找并找到它不期望的版本。
Note that the compiler DOES NOT use the GAC when referencing assemblies. So most probably you have a different version used as a reference in the project than you have installed in the GAC.
请注意,编译器在引用程序集时不使用 GAC。因此,很可能您在项目中用作参考的版本与您在 GAC 中安装的版本不同。
Also, it is very easy to find out what version you have installed in the GAC by looking in C:\Windows\assembly using Windows Explorer. The version that is specified in your error message will be the version that was referenced during compilation. If these versions don't match this could be your problem, assuming that Fusion is indeed looking in the GAC (which will be evident by looking in the Fusion log).
此外,通过使用 Windows 资源管理器查看 C:\Windows\assembly,可以很容易地找出您在 GAC 中安装的版本。错误消息中指定的版本将是编译期间引用的版本。如果这些版本不匹配,这可能是您的问题,假设 Fusion 确实在 GAC 中查找(通过查看 Fusion 日志可以看出这一点)。