C#: 无法从程序集中加载类型

标签 c# windows visual-studio dll lucene.net

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

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

注意:Contrib.Regex 是 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 = rcw7\Me
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:\Development\Projects\Foobar\Foobar\bin
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:\Development\Projects\Foobar\Foobar\web.config
LOG: Using host configuration file: C:\Users\Me\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.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

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

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

最佳答案

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

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

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

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

正确的 解决方案可能是告诉应用程序它应该忽略以前版本的 Lucene.NET,但到目前为止我还没有遇到任何运气。这是我添加到 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>

这似乎没有任何效果,过时的版本仍然在影子缓存中。我已将此问题移至此处:How do I make Umbraco 5 ignore the bundled (with Examine) Lucene.NET

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

关于C#: 无法从程序集中加载类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10297961/

相关文章:

c# - 如果页面不是回发

c# - CaSTLe ResolveAll 返回空数组

windows - 在 Amazon EC2 Windows 2008 镜像上运行 Win32 可执行文件

c++ - 从 exe 入口点返回不会终止 Windows 10 上的进程

java - 如何在 Windows 中查看正在执行的 java 程序的类路径和 jvm args

visual-studio - 有没有办法强制 visual studio 从 SSE 内在函数生成对齐的指令?

c# - RSI vs Wilder 的 RSI 计算问题

c# - 如何发送ctrl+z

C# 安全异常

c++ - 从 Visual Studio 启动时,发布构建速度比启动 "normally"更快