原文链接

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. VUE项目注意点

    1.vue组件中img标签的src属性绑定数据: <img :src="img" alt="图片" /> //scriptdata() { img: ...

  2. Visual Studio 2017的一些使用记录

    只要在整个项目组里加一个新的项目,vs就会去自动修改sln文件 新加一个项目的理解为:菜单里 File->New->Project一个项目编译后生成1个dll文件 sln是文本文件只有vs ...

  3. PowerBI/Excel - PowerQuery数据转换系列 - 如何将多行的值串联到一行 - 行列转换

    Power Query 是做数据转换.数据清洗的利器,不管是在Excel还是PowerBI,如何玩好Power Query是成功建模的必不可少的一步. 今天要get到的一个新技巧:行列转换 如何将多行 ...

  4. 【菜鸟学Python】案例一:汇率换算

    汇率换算V1.0 案例描述: 设计一个汇率换算器程序,其功能是将外币换算成人民币,或者相反 案例分析: 分析问题:分析问题的计算部分: 确定问题:将问题划分为输入.处理及输出部分: 设计算法:计算部分 ...

  5. IR2104s半桥驱动使用经验

    多次使用IR2104s,每次的调试都有种让人吐血的冲动.现在将使用过程遇到的错误给大家分享一下,方便大家找到思路. 一.自举电容部分(关键) 1.听说自举电路必须要安装场效应管,于是我在使用过程中,安 ...

  6. git使用手册整理

    -------------------20181217------------------- git使用:在gitbash 下初始化用户: $ git config --global user.nam ...

  7. Fiddler抓包【3】_设置断点修改

    1. 断点修改Request 1.1.Request全部中断 设置中断:Rules---> Automatic Breakpoints--->Before Requests 取消中断:Ru ...

  8. vue进阶--外卖商家页

    一.准备工作 1.vue特性:轻量级.简洁.高效.组件化.数据驱动 2.技术分析:使用vue- resource与后端交互(ajax通信,ie9+)  使用vue-router作为前端路由   bet ...

  9. P1772 [ZJOI2006]物流运输

    题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪. ...

  10. pycharm2018安装教程 pycharm2018永久激活教程

    安装教程 下载pycharm 2018.3.2安装文件,可以直接点击下载网盘下载 激活码地址:http://demo.liuy88.cn/jp0876.html 下载完成后,双击exe即可开始安装 点 ...