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

Sau*_*rup 12 c# windows dll lucene.net visual-studio

在将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'
Run Code Online (Sandbox Code Playgroud)

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

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

任何建议如何克服这个?:-)

Sau*_*rup 7

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

显然,过时的,捆绑的Lucene.NET最终进入了影子缓存(Temporary ASP.NET Files),因此在下次编译或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>
Run Code Online (Sandbox Code Playgroud)

这似乎没有任何影响,过时的版本仍然在影子缓存中结束.我在这里提出了这个问题:如何让Umbraco 5忽略捆绑(使用检查)Lucene.NET

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