“无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Validation”例外
我当前在尝试使用企业库验证应用程序块时遇到以下异常:
创建用于验证的配置节处理程序时发生错误:无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Validation,版本=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)
我知道异常试图告诉我什么,但是我不知道如何解决它。我只安装过一个版本的企业库,就是它(4.1.0.0),所以我不明白它如何找到错误的版本,所以我想这是一个依赖问题。我已将 Enterprise Library 4.1 中的“Common”、“Validation”和“ObjectBuilder2”DLL 作为项目中的引用包含在内,所以我不确定还缺少什么。该文档似乎表明这就是我所需要的。
有什么方法可以追踪依赖性问题是什么?
如果有帮助,我尝试使用企业库配置工具创建验证应用程序块规则集,以验证实体框架实体中的数据。我在 Visual Studio 2008 中使用 ASP.NET MVC。
感谢您提供的任何帮助/指导,
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)
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.
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.
Thanks for any assistance/direction you can provide,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
打开 Fusion 日志记录并查看运行时绑定的程序集。
Hanselman 最近发表了一篇文章,应该有助于启用日志记录和检查输出。
http://www.hanselman.com/blog /CommentView.aspx?guid=3654c8f3-c5c3-4dee-a01f-c9a8da3ef2fa
另一个重要的区别是添加到项目中的引用是编译时引用,不会影响代码的绑定方式在运行时,而不是在使用强命名程序集时指定强名称。为了找出运行时发生的情况,您需要查看绑定日志。日志应该显示运行时在定位程序集时所做的所有尝试。如果程序集不与可执行文件一起位于 bin 目录中,则很可能会在 GAC 中查找并找到它不期望的版本。
请注意,编译器在引用程序集时不使用 GAC。因此,您在项目中用作参考的版本很可能与 GAC 中安装的版本不同。
此外,通过使用 Windows 资源管理器查看 C:\Windows\Assembly,可以很容易地找出您在 GAC 中安装的版本。错误消息中指定的版本将是编译期间引用的版本。如果这些版本不匹配,这可能是您的问题,假设 Fusion 确实在 GAC 中查找(通过查看 Fusion 日志可以明显看出)。
Turn on Fusion logging and see what assembly is being bound at runtime.
Hanselman had a post recently that should be helpful in enabling logging and examining the output.
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.
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.
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).