C# 定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16425549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
提问by lioni jordan
After signing the third parties assemblies and adding them to GAC I am getting the below error: also the Assembly Binder Log Entry shows this error
签署第三方程序集并将它们添加到 GAC 后,我收到以下错误:程序集绑定器日志条目也显示此错误
It says mismatching assemblies not sure how mistnaching as I deleted all obj and bin fold and batch built the application + reimported the dlls.
它说不匹配的程序集不确定我删除了所有 obj 和 bin fold 并批量构建应用程序 + 重新导入了 dll。
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer.0\WebDev.WebServer40.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = AKBARCA\user
LOG: DisplayName = ClubStarterKit.Core, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase =
file:///C:/Users/user/Desktop/NhibernateMediumTrust/NhibernateMediumUpgrade/direct/clubstar
terkit v3 preview/ClubStarterKit.Web/
LOG: DEVPATH = C:\ProgramData\Red Gate\.NET Reflector\DevPath
LOG: Initial PrivatePath =
C:\Users\user\Desktop\NhibernateMediumTrust\NhibernateMediumUpgrade\direct\clubstarterkit v3 preview\ClubStarterKit.Web\bin
Calling assembly : ClubStarterKit.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
回答by Chris Pratt
From my experience, this happens, usually once you've published your app and when you have different versions of nuget packages in play. If this happens to be your situation as well, the best way I've found to fix it is to right-click the solution(not the individual projects) and choose "Manage Nuget Packages". Then, locate the offending assembly in the installed packages. You'll probably see it listed multiple times. Click "Manage" on each of the older versions of the package and uncheck all your projects. Once only the latest version of the package remains in the list. Click "Manage" on this one and recheck any projects that need the package. This will essentially upgrade them all to use the same version of the package and should resolve your mismatch error.
根据我的经验,这种情况通常会在您发布应用程序以及使用不同版本的 nuget 软件包时发生。如果这恰好也是您的情况,我发现解决它的最佳方法是右键单击解决方案(而不是单个项目)并选择“管理 Nuget 包”。然后,在已安装的包中找到有问题的程序集。您可能会看到它多次列出。在每个旧版本的包上单击“管理”并取消选中所有项目。一旦只有最新版本的包保留在列表中。单击此项目上的“管理”并重新检查任何需要该包的项目。这将从本质上升级它们以使用相同版本的包,并应解决您的不匹配错误。
回答by Brij
I faced similar problem. In my case, I was having multiple projects in my solution.
我遇到了类似的问题。就我而言,我的解决方案中有多个项目。
One of the project was referring EntityFramework 4.0 and that project was being referred in another project that was referring to EntityFramework 5.0. I brought them in sync and the problem got away.
其中一个项目引用了 EntityFramework 4.0,而另一个项目引用了该项目,该项目引用了 EntityFramework 5.0。我使它们同步,问题就解决了。
回答by bresleveloper
When I experienced this problem in the past, I deleted all my project's dll's from the gac, rebuilt the solution, then did iisresetand it was solved.
当我过去遇到这个问题时,我从gac中删除了我所有项目的dll,重建了解决方案,然后这样做了iisreset,它解决了。
回答by Lincoln Pires
Hum... I faced something similar with the same error message.
嗯......我遇到了类似的错误信息。
In my case I've updated manually the version of the assemblies.
就我而言,我已经手动更新了程序集的版本。


In the referenced assembly I had another version...
在引用的程序集中我有另一个版本......
So, I updated it in the web.config.
所以,我在 web.config 中更新了它。


This solved my problem.
这解决了我的问题。
Your === Pre-bind state information ===seems incomplete.
Generally it shows the execution and the last line shows the error, so, we can help only sharing our experiences.
Example:

你的=== Pre-bind state information ===好像不完整。一般它显示执行,最后一行显示错误,因此,我们只能帮助分享我们的经验。例子:

I hope someone else facing this problem find this helpful.
我希望遇到此问题的其他人会发现这有帮助。
回答by C. Deng
In my case, the error happens when the version specified in web.config's <bindingRedirect>of the dependent assembly (e.g. Newtonsoft.Json) doesn't match the version that is actually in the bin folder. Once the version number in the web.config is updated, the problem is fixed.
就我而言,当<bindingRedirect>依赖程序集(例如 Newtonsoft.Json)的web.config 中指定的版本与 bin 文件夹中的实际版本不匹配时,就会发生错误。一旦 web.config 中的版本号更新,问题就解决了。


回答by Jeremy Thompson
I got this error using FASTjson:
我使用FASTjson收到此错误:
_jsonConfig = fastJSON.JSON.ToObject<jsonConfig>(jsonConfigFileContents);
_jsonConfig = fastJSON.JSON.ToObject<jsonConfig>(jsonConfigFileContents);
It failed on this line:
它在这条线上失败了:
Type t = Type.GetType(typename);
Type t = Type.GetType(typename);
Which causes an exception in System.RuntimeTypeHandle.GetTypeByName
这会导致System.RuntimeTypeHandle.GetTypeByName 中的异常
The problem was a difference in the JSON file compared to the JSON Object Model.
问题在于 JSON 文件与 JSON 对象模型相比有所不同。
The solution is to re-savethe JSON Object Model to file, eg:
解决方案是将 JSON 对象模型重新保存到文件中,例如:
string jsonSettings = fastJSON.JSON.ToJSON(JSONObjectModel);
File.WriteAllText(JSONFilePath, jsonSettings);
回答by Mauro Bilotti
One way to solve this could be, going under "Manage NuGet Packages for Solution" by doing right click in the solution explorer. Once there, go to "Consolidate"and find the package that is causing the problems. Make sure that all the projects within the solution are using the same version.
解决此问题的一种方法可能是,通过在解决方案资源管理器中右键单击进入“管理解决方案的 NuGet 包”。在那里,转到“合并”并找到导致问题的包。确保解决方案中的所有项目都使用相同的版本。
回答by iJungleBoy
I had a different cause: in my case, I had used various nuget package versions previously, and I had an app.configwhich for some reason had been automatically generated with this kind of content:
我有一个不同的原因:在我的情况下,我以前使用过各种 nuget 包版本,并且app.config由于某种原因,我使用这种内容自动生成了一个:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
</dependentAssembly>
So I only had Version 1.1.0.0 installed, but because of this redirect instruction, it looked for 1.1.1.0 even though Visual Studio had the nuget for 1.1.0.0 installed. Changing the newVersion to 1.1.0.0 fixed everything:
所以我只安装了 1.1.0.0 版,但由于这个重定向指令,即使 Visual Studio 安装了 1.1.0.0 的 nuget,它也会寻找 1.1.1.0。将 newVersion 更改为 1.1.0.0 修复了所有问题:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.0.0" />
</dependentAssembly>

