原文链接

Could you be missing the loaded assembly from your configuration file?

Ensure you have something similar to the following within your web.config. NuGet would normally do this but maybe it hasn't and it doesn't know what to load in

<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>

  

Apparently this can be solved by adding a <qualifyAssembly> element to the app.config file. Adding the following has my app running smoothly:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="System.Data.SqlServerCe" fullName="System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</assemblyBinding>
</runtime>

yeah the fullName referred to above is indeed the full name for the assembly. It gives the CLR the info it needs to find and load the specific assembly. You can also substitute that fullName in a connection string in a .config file (in place of the partialName)

原文3 

Remove all the references to Newtonsoft.Json in all your projects.

Go to Nuget Package Manager (right click on solution), download Newtonsoft.Json latest version and select all the projects to use it, and reinstall it.

Make sure the packages.config have the latest version:

<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
</packages>

Rebuild solution.

This is one of the most common problems in .NET projects.

Basically someone made a reference directly to an local assembly instead of managing the package via NuGet or the project was made to compile in a different .NET version.

The best way to solve this is to locate the reference in your project references, remove it, clean the project, check if the DLL has gone and finally remake the reference using NuGet.

 

try clean your project.

Clean Project in Visual Studio

If this don't work, remove the reference under references. Save the dll file in your bin folder and then add it again. Browse your file, select it and click in ok.

I had a similar issue when I had two different projects within the same solution, in which one of them is referring to version 11.0.2 and the other is referring to version 6.0.4. If this is the case, try keeping the same version for both of them and retry.

原文4

Some time it happens because the oracle dll is 32 bit and your application is build on 64 bit changing the app to 32 bit may solve your problem

if the reason is 32/64 mixup i causes a BadImageFormatException

原文5

When I attempted to duplicate the problem, the error went away after I ran a NuGet update for System.Runtime.CompilerServices.Unsafe.

It looks like a new dependency with the latest Unity version (v5.9.3) and there is a configuration problem with a version of the dependent package. If you want to know more you can read stackoverflow.com/questions/215026/… and stackoverflow.com/questions/20978519/…

Jasen is correct if your NuGet plays nicely with your project, but I wasn't so lucky (when I tried re-adding the package, I got the same error).

What fixes the bug is adding a dependentAssembly entry for the 'missing' assembly inside your app/web config (which is the magic behind the NuGet install, and should happen automatically).

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
...

  

原文6:Could not load file or assembly 'xxx' or one of its dependencies. An attempt was made to load a program with an incorrect format

Sounds like one part of the project is being built for x86-only while the rest is being built for any CPU/x64. This bit me, too. Are you running an x64 (or uh... IA64)?

Check the project properties and make sure everything is being built for "Any CPU". if you're in Visual Studio, you can check for everything by going to the "x86" or "Any CPU" menu (next to the "Debug"/"Release" menu) on the toolbar at the top of the screen and clicking "Configuration Manager..."

If you get this error while running the site in IIS 7+ on 64bit servers, you may have assemblies that are 32bit and your application pool will have the option "Enable 32-Bit Applications" set to False; Set this to true and restart the site to get it working.

Same here. It depends on where the error occurs. If it's through Visual Studio & Cassini web server, Fraser's right. If it occurs in IIS7+, Nicks answer is probably the most likely fix.

This was teh perfect answer for me (moved a site from IIS6 on x86 to IIS 7 on x64)

The BadImageFormatException on an application running on IIS (not running from VS, since visual studio fixes the problem by using the build for "Any CPU") can be caused by the following:

The site is one a server that is x64 and the Application Pool's default setting for Enable 32-Bit Applications was False. and you have 32-bit assemblies

On the level of Visual Studio, the fix is:

  1. Change the project setting "Target CPU" to "ANYCPU"

inetmgr then come to Application pool->Advanced setting of your pool-> will have the option "Enable 32-Bit Applications" set to true; and restart IIS. check again.!

if while In visual studio with IIS express working and when published failed try this:

原文7:Could not load file or assembly … An attempt was made to load a program with an incorrect format (System.BadImageFormatException)

Things I have tried:

  • Make sure both projects are set to "Any CPU," with the build checkbox checked. They are.
  • Make sure both projects are for the same Target Framework (.Net 4.0 Client Profile).
  • Under ProjectB --> References --> ProjectA --> Properties, make sure "Copy Local" is set to "True" _ (I verified that ProjectA.dll is being copied correctly)
  • Clean/Rebuild the solution. I even tried manually deleting the /bin and /obj folders in both projects.
  • Restart Visual Studio. Restart my computer.
  • Check out an entirely new copy of the repository.

But I still get the same error. I have no idea what I did to cause this, nor how to fix it. Any ideas?

i am pretty sure you're having a 32-bit / 64-bit conflict. It sounds like your main project might be set to 32-bit while the class its referencing is set to 64-bit. Try looking at this SO question and this one too. Between the two of them, you should be able to figure out your problem.

Do'h. I somehow completely missing "platform target" dropdown in project-->properties-->build - it was set for x86; setting it to "Any CPU" fixed this issue. I always thought that this setting was the same as the "platform target" dropdown in the configuration manager, but apparently it's not (in fact, the "platform target" in configuration manager doesn't appear to do anything at all!)

PS: Another reason is "Enable 32-bit applications" being "false" in app pool settings. You need to restart IIS after setting it to true.

Might be you are facing the problem with your website after deploying on server.

Then you need to adjust your application pool to Enable 32-Bit Applications.

Steps:

  1. Open IIS Manager
  2. Click on Application Pools
  3. Select whatever application pool you are using
  4. From right pane, click Advanced Settings...
  5. Set Enable 32-Bit Applications to True

I just had this error message running IIS Express in Visual Studio 2015. In my case I needed to be running the 64 bit version of IIS Express:

Tools -> Options -> Projects and Solutions -> Web Projects
Check the box that says "Use the 64 bit version of IIS Express for web sites and projects".

原文8:The located assembly's manifest definition does not match the assembly reference

The .NET Assembly loader is unable to find 1.2.0.203, but did find a 1.2.0.200. This assembly does not match what was requested and therefore you get this error. In simple words, it can't find the assembly that was referenced. Make sure it can find the right assembly by putting it in the GAC or in the application path. Also see http://blogs.msdn.com/junfeng/archive/2004/03/25/95826.aspx.

Check the references version, and then look if its the same in packages.config and Web.config

you can do a couple of things to troubleshoot this issue.

First, use Windows file search to search your hard drive for your assembly (.dll). Once you have a list of results, do View->Choose Details... and then check "File Version". This will display the version number in the list of results, so you can see where the old version might be coming from.

Also, like Lars said, check your GAC to see what version is listed there. This Microsoft article states that assemblies found in the GAC are not copied locally during a build, so you might need to remove the old version before doing a rebuild all. (See my answer to this question for notes on creating a batch file to do this for you)

If you still can't figure out where the old version is coming from, you can use the fuslogvw.exe application that ships with Visual Studio to get more information about the binding failures. Microsoft has information about this tool here. Note that you'll have to enable logging by setting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog registry key to 1.

 

I just ran into this problem myself, and I found that the issue was something different than what the others have run into.

I had two DLLs that my main project was referencing: CompanyClasses.dll and CompanyControls.dll. I was getting a run-time error saying:

Could not load file or assembly 'CompanyClasses, Version=1.4.1.0, Culture=neutral, PublicKeyToken=045746ba8544160c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference

Trouble was, I didn't have any CompanyClasses.dll files on my system with a version number of 1.4.1. None in the GAC, none in the app folders...none anywhere. I searched my entire hard drive. All the CompanyClasses.dll files I had were 1.4.2.

The real problem, I found, was that CompanyControls.dll referenced version 1.4.1 of CompanyClasses.dll. I just recompiled CompanyControls.dll (after having it reference CompanyClasses.dll 1.4.2) and this error went away for me.

Another option would be to open the CompanyControls project, right-click the CompanyClasses.dllreference --> properties --> SpecificVersion = false

The following redirects any assembly version to version 3.1.0.0. We have a script that will always update this reference in the App.config so we never have to deal with this issue again.

Through reflection you can get the assembly publicKeyToken and generate this block from the .dll file itself.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="3.1.0.0" />
</dependentAssembly>
</assemblyBinding>

  

My issue was the fact that the redirects were pointing to non-existent assemblies.The App.Config held assembly info from the latest NuGet packages I'd installed. When I downgraded these packages later, it did NOT clean this up. This was a .NET standard class library being hit by a 4.7.2 framework unit test project. The unit test project's issue presented at runtime..

is right. If your source control indicates that web.config has changes (because you've been playing with your NuGets) you might be wise to back those bindingRedirects out of there. Downgrading NuGets will not clean up the binding redirects

If you are using Visual Studio, try "clean solution" and then rebuild your project.

This is usually the solution for me. Often, deleting bin and obj do it. Basically, something I used to reference is still sitting there trying to satisfy the same requirement. For example, an old version being something I referenced directly and the new version being on NuGet

The other answers wouldn't work for me. If you don't care about the version and you just want your app to run then right click on the reference and set 'specific version' to false...This worked for me

That setting has only effect at compile time. After it is compiled, it will need the exact same assembly version with which you compiled it. See stackoverflow.com/questions/24022134/…

In my case, this error occurred while running an ASP.NET application. The solution was to:

  1. Delete the obj and bin folders in the project folder

Clean didn't work, rebuild didn't work, all references were fine, but it wasn't writing one of the libraries. After deleting those directories, everything worked perfectly.

This exact same error is thrown if you try to late bind using reflection, if the assembly you are binding to gets strong-named or has its public-key token changed. The error is the same even though there is not actually any assembly found with the specified public key token.

You need to add the correct public key token (you can get it using sn -T on the dll) to resolve the error. Hope this helps.

"sn.exe" is a tool that comes with Visual Studio, it's a command line tool that can be run from the Visual Studio command prompt. Just run the Visual Studio command prompt (from the start menu), navigate to the folder that contains your assembly, and type "sn -T <assembly>" where <assembly> is the full name of the dll. This gets the Assembly "Token" information. Once you have this, when you are doing late binding with reflection, enter the token info into the assembly id string (i.e., "Assembly=MyAssembly.dll, Public Key Token=<token guid>) –

I would like to just add that I was creating a basic ASP.NET MVC 4 project and added DotNetOpenAuth.AspNet via NuGet. This resulted in the same error after I referenced a mismatching DLL file for Microsoft.Web.WebPages.OAuth.

To fix it I did a Update-Package and cleaned the solution for a full rebuild.

That worked for me and is kind of a lazy way, but time is money:-P

Similar answer for me. Update-Package -reinstall re-installs all NuGet packages at the same version.

error_Could not load file or assembly的更多相关文章

  1. configuration error-could not load file or assembly crystaldecisions.reportappserver.clientdoc

    IIS启动网站后报错: configuration error Could not load file or assembly 'crystaldecisions.reportappserver.cl ...

  2. Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its de

    页面加载时出现这个错误: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Cul ...

  3. Could not load file or assembly 'System.ServiceModel.DomainServices.Hosting'.系统找不到指定文件

    项目部署到服务器后出现如下错误信息: Parser Error Message: Could not load file or assembly 'System.ServiceModel.Domain ...

  4. ASP.NET corrupt assembly “Could not load file or assembly App_Web_*

    以下是从overFlow 复制过来的问题 I've read through many of the other questions posted on the same issue, but I s ...

  5. Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0 系统找不到指定的文件。

    环境: web服务器: ip:192.168.1.32 ,安装有 Visual Studio Premium 2013 操作系统: Microsoft  Server 2008 r2+sp1 数据库服 ...

  6. NopCommerce 发布时 Could not load file or assembly 'file:///...\Autofac.3.5.2\lib\net40\Autofac.dll' or one of its dependencies

    本文转自:http://www.nopcommerce.com/boards/t/33637/4-errors.aspx 问题: The 3.5 solution compiles fine, and ...

  7. Could not load file or assembly 'MySql.Data.CF,

    Could not load file or assembly 'MySql.Data.CF, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c56 ...

  8. Could not load file or assembly 'System.Data.SQLite' or one of its dependencies

    试图加载格式不正确的程 异常类型 异常消息Could not load file or assembly 'System.Data.SQLite' or one of its dependencies ...

  9. System.BadImageFormatException: Could not load file or assembly

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe C:\_PRODUKCIJA\Debug\DynamicHtmlT ...

随机推荐

  1. 移动端适配--flexible.js

    引言: H5适配一直是一个比较普遍的问题,很多文章都会讲,最近开发了一个H5的项目使用了一下淘宝的 flexible.js,写一篇文章自己总结一下. 一.背景介绍: Flexible.js是淘宝公开的 ...

  2. [Freemarker]自定义时间戳函数

    使用freemarker的web项目经常需要用在Url后面加上时间戳来保证资源不被缓存,我们可以自定义方法实现时间戳. 先看freemarker配置信息: <bean id="free ...

  3. JS生成当前月份包括最近12个月内的月份

    var last_year_month = function() { var result = []; for(var i = 0; i < 12; i++) { var d = new Dat ...

  4. 10个Python基础练习项目,你可能不会想到练手教程还这么有趣

    美国20世纪最重要的实用主义哲学家约翰·杜威提出一个学习方法,叫做:Learning By Doing,在实践中精进.胡适.陶行知.张伯苓.蒋梦麟等都曾是他的学生,杜威的哲学也影响了蔡元培.晏阳初等人 ...

  5. JMeter-正则表达式(HTML)

    2019-04-26问题:需要取出交易成功,但是有黄色部分 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  6. 使用TCP模拟登陆

    import java.util.ArrayList;import java.util.List; public class UserDB { //使用Map存储账号密码 private static ...

  7. ubuntu 16.04 国内仓库地址

    deb http://mirrors.aliyun.com/ubuntu xenial maindeb http://mirrors.aliyun.com/ubuntu xenial universe ...

  8. Cocos Creator 获取当前 Pageview 翻页到第几页的事件索引

    新建一个js,叫做 pageAction写一个方法 pageViewClick:function(event,coustom){ var node = event.node; this.pageInd ...

  9. Backup &recovery备份和还原

    实践版本:MySQL5.7 备份类型(backup type)物理和逻辑备份(Physical Versus Logical Backup)        物理备份是指直接复制存储数据库内容的目录和文 ...

  10. Spring AOP capabilities and goals

    Spring AOP 是用纯JAVA 实现的. 不需借助JAVA代码在编译处理阶段来实现. Spring 是在运行期实现的.AOP的实现可以在编译,加载,运行三个阶段来实现:Spring AOP 也不 ...