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

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

问题描述

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



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



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

 '/'应用程序中的服务器错误。 

无法从程序集加载类型Contrib.Regex,Version = 2.9.4.0,Culture = neutral,PublicKeyToken = 85089178b9ac3181,errors:
异常:System.IO.FileLoadException:无法加载文件或者汇编Lucene.Net,Version = 2.9.4.1,Culture = neutral,PublicKeyToken = 85089178b9ac3181或其依赖关系之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT的异常:0x80131040)
文件名:Lucene.Net,Version = 2.9.4.1,Culture = neutral,PublicKeyToken = 85089178b9ac3181'

===预绑定状态信息= ==
日志:用户= rcw7\Me
日志:DisplayName = Lucene.Net,Version = 2.9.4.1,Culture = neutral,PublicKeyToken = 85089178b9ac3181
(完全指定)
LOG:Appbase = file:/// C:/ Development / Projects / Foobar / Foobar /
LOG:Initial PrivatePath = C:\Development\Projects\Foobar\Foobar\bin
调用程序集:Contrib.Regex,Version = 2.9.4.0,Culture = neutral,PublicKeyToken = 85089178b9ac3181。
===
日志:此绑定在默认加载上下文中启动。
日志:使用应用程序配置文件:C:\Development\Projects\Foobar\Foobar\web.config
日志:使用主机配置文件:C:\Users\Me\\ \\ Documents\IISExpress\config\aspnet.config
日志:使用机器配置文件从C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config 。
日志:政策参考:Lucene.Net,Version = 2.9.4.1,Culture = neutral,PublicKeyToken = 85089178b9ac3181
日志:尝试下载新的URL文件:/// C:/ Users / Me / AppData / Local / Temp / Temporary / ASP.NET文件/ root / e9b4cfa4 / edfa73f8 / Lucene.Net.DLL。
WRN:比较程序集名称导致不匹配:修订号
ERR:无法完成程序集的设置(hr = 0x80131040)。探测终止
异常:System.IO.FileLoadException:无法加载文件或程序集Lucene.Net,Version = 2.9.4.1,Culture = neutral,PublicKeyToken = 85089178b9ac3181或其一个依赖项。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT的异常:0x80131040)
文件名:Lucene.Net,Version = 2.9.4.1,Culture = neutral,PublicKeyToken = 85089178b9ac3181'

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



最初我以为这是我的开发环境的本地问题,但是在将项目重建和复制到我们的服务器之后,我收到相同的错误。 b
$ b

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

解决方案

事实证明,DLL本身并不是由我自己的配置和编译库引起的。这实际上是由于我新下载的Lucene.NET版本与Examin捆绑在一起的版本之间的冲突引起的,后者又与Umbraco 5捆绑在一起。



显然,过时的捆绑的Lucene.NET最终在影子缓存(Temporary ASP.NET Files)中,所以在下一次编译或IIS重新启动后,执行会中断。清除影子缓存将允许一个成功执行。



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



快速的解决方案是简单地压缩检查插件,所以Umbraco不会看到它。那没有检查插件,我没有使用,但是我还没有使用它。



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

 < dependentAssembly> 
< assemblyIdentity name =Lucene.NetpublicKeyToken =85089178b9ac3181culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-2.9.4.1newVersion =2.9.4.1/>
< / dependentAssembly>

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

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:\Users\Me\AppData\Local\Temp\Temporary ASP.NET Files before I can run the project again.

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:

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 = 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'

Full output here: 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? :-)

解决方案

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.

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.

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_Plugins\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.

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>

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天全站免登陆