C#:无法从程序集中加载类型 [英] C#: Could not load types from assembly

查看:29
本文介绍了C#:无法从程序集中加载类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 Lucene.net 和 Lucene.net Contrib 添加到 C# MVC3 后,我在第一次成功运行后收到以下消息.收到此错误后,我需要完全擦除 C:UsersMeAppDataLocalTempTemporary ASP.NET Files 才能再次运行该项目.

After adding Lucene.net and Lucene.net Contrib to a C# MVC3, I get the message below after the first successful run. After receiving this error, I need to completely wipe C:UsersMeAppDataLocalTempTemporary ASP.NET Files before I can run the project again.

我尝试手动删除 Lucene 文件(包括我的项目中的引用),并重新安装它们 - 使用 NuGet 和手动 - 但它总是相同的情况;项目运行一次后,我开始收到以下错误:

I've tried removing the Lucene files manually (including references in my project), and reinstalling them - both with NuGet and manually - but it's always the same situation; after the project has been run once, I start getting the following errors:

注意:Contrib.Regex 是 Lucene.net Contrib 的一部分.

Note: Contrib.Regex is part of Lucene.net Contrib.

Server Error in '/' Application.

Could not load types from assembly Contrib.Regex, Version=2.9.4.0, Culture=neutral, PublicKeyToken=85089178b9ac3181, errors:
Exception: System.IO.FileLoadException: Could not load file or assembly 'Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181'

=== Pre-bind state information ===
LOG: User = rcw7Me
LOG: DisplayName = Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181
(Fully-specified)
LOG: Appbase = file:///C:/Development/Projects/Foobar/Foobar/
LOG: Initial PrivatePath = C:DevelopmentProjectsFoobarFoobarin
Calling assembly : Contrib.Regex, Version=2.9.4.0, Culture=neutral, PublicKeyToken=85089178b9ac3181.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:DevelopmentProjectsFoobarFoobarweb.config
LOG: Using host configuration file: C:UsersMeDocumentsIISExpressconfigaspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.
LOG: Post-policy reference: Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181
LOG: Attempting download of new URL file:///C:/Users/Me/AppData/Local/Temp/Temporary ASP.NET Files/root/e9b4cfa4/edfa73f8/Lucene.Net.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Exception: System.IO.FileLoadException: Could not load file or assembly 'Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181'

完整输出:http://pastebin.com/Vbu4VK7B

最初我认为这是我的开发环境的本地问题,但在重建项目并将其复制到我们的服务器后,我遇到了同样的错误.

Initially I thought this was a problem local to my development environment, but after rebuilding and copying the project to our server, I get the same errors.

关于如何克服这个问题有什么建议吗?:-)

Any suggestions as how to overcome this? :-)

推荐答案

事实证明,DLL 地狱并不是我自己干预配置和编译库造成的.它实际上是由我新下载的 Lucene.NET 版本与 Examine 捆绑的有些过时的版本之间的冲突引起的,后者又与 Umbraco 5 捆绑在一起.

As it turns out, the DLL hell wasn't caused by my own meddling in configurations and compiled libraries. It was in fact caused by a collision between my newly downloaded version of Lucene.NET and a somewhat dated version bundled with Examine, which in turn was bundled with Umbraco 5.

显然,过时的、捆绑的 Lucene.NET 最终出现在影子缓存(临时 ASP.NET 文件)中,因此在下一次编译或 IIS 重新启动后,执行将中断.清除影子缓存将允许一次成功执行.

Apparently the outdated, bundled Lucene.NET ended up in the shadow cache (Temporary ASP.NET Files), so after the next compile or IIS restart, execution would break. Clearing the shadow cache would allow for one success execution.

奇怪的是,我无法在调试输出中的任何地方找到任何暗示 Lucene.NET 过时版本的参考,无论是目录路径还是版本号.问题是通过比较 Lucene.NET 的影子复制版本和我打算使用的版本的文件大小来发现的.他们关闭了,所以我搜索了 Lucene.NET.dll 并在 Umbraco 树中找到了与 Examine 捆绑在一起的那个(在 App_PluginsExamine 下)

The weird thing was, that I was unable to find any reference anywhere in the debug output that hinted to the outdated version of Lucene.NET, either with a directory path or version number. The problem was spotted by comparing the file sizes of the shadow copied version of Lucene.NET and the version I intended to use. They were off, so I did a search for Lucene.NET.dll and found the one bundled with Examine in the Umbraco tree (under App_PluginsExamine)

快速的解决方案是简单地压缩 Examine 插件,这样 Umbraco 就不会看到它.这让我没有了 Examine 插件,但我还是没有使用它.

The fast solution was to simply zip the Examine plugin, so Umbraco wouldn't see it. That leaves me without the Examine plugin, but I wasn't using it anyway.

正确 解决方案可能是告诉应用程序它应该忽略以前版本的 Lucene.NET,但到目前为止我还没有任何运气.这是我添加到 web.config 的内容:

The right solution would probably be to tell the app that it should ignore previous versions of Lucene.NET, but I haven't had any luck with that so far. This is what I added to web.config:

<dependentAssembly>
    <assemblyIdentity name="Lucene.Net" publicKeyToken="85089178b9ac3181" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.9.4.1" newVersion="2.9.4.1" />
</dependentAssembly>

这似乎没有任何影响,过时的版本仍然在影子缓存中结束.我已将这个问题移至此处:如何让 Umbraco 5 忽略捆绑的(带检查)Lucene.NET

This didn't seem to have any effect, and the outdated version still ended up in the shadow cache. I've moved this question here: How do I make Umbraco 5 ignore the bundled (with Examine) Lucene.NET

感谢您的帮助和建议 - 它为我指明了正确的方向!:-)

Thanks for your help and suggestions - it pointed me in the right direction! :-)

这篇关于C#:无法从程序集中加载类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆