Ошибка could not load file or assembly

I’m having another of these «Could not load file or assembly or one of its dependencies» problems.

Additional information: Could not load
file or assembly
‘Microsoft.Practices.Unity,
Version=1.2.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35’ or
one of its dependencies. The located
assembly’s manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)

I have no idea what is causing this or how I could debug it to find the cause.

I’ve done a search in my solution catalogs .csproj files, and every where I have Unity I have:

Reference
Include=»Microsoft.Practices.Unity,
Version=2.0.414.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35,
processorArchitecture=MSIL»

Can’t find any reference anywhere which goes against 1.2.0.0 in any of my projects.

Any ideas how I should go about solving this?

TylerH's user avatar

TylerH

20.7k65 gold badges73 silver badges98 bronze badges

asked Dec 17, 2010 at 11:13

ronag's user avatar

7

  1. Check if you are referencing an assembly which in turn referencing an old version of unity. For example let’s say you have an assembly called ServiceLocator.dll which needs an old version of Unity assembly, now when you reference the ServiceLocator you should provide it with the old version of Unity, and that makes the problem.

  2. May be the output folder where all projects build their assemblies, has an old version of unity.

You can use FusLogVw to find out who is loading the old assemblies, just define a path for the log, and run your solution, then check (in FusLogvw) the first line where the Unity assembly is loaded, double click it and see the calling assembly, and here you go.

Slime recipe's user avatar

Slime recipe

2,2133 gold badges32 silver badges49 bronze badges

answered Dec 17, 2010 at 11:30

Nour's user avatar

NourNour

5,1923 gold badges41 silver badges65 bronze badges

2

Open IIS Manager

Select Application Pools

then select the pool you are using

go to advanced settings (at right side)

Change the flag of Enable 32-bit application false to true.

answered Oct 7, 2013 at 10:58

kranthi's user avatar

kranthikranthi

9656 silver badges2 bronze badges

4

For me, none of the other solutions worked (including the clean/rebuild strategy). I found another workaround solution which is to close and re-open Visual Studio.

I guess this forces Visual Studio to re-load the solution and all the projects, rechecking the dependencies in the process.

answered Feb 15, 2012 at 5:27

Robotnik's user avatar

RobotnikRobotnik

3,6133 gold badges31 silver badges49 bronze badges

1

Try to clean Debug and Release folders in your solution. Then remove and add unity again.

BlaM's user avatar

BlaM

28.3k32 gold badges90 silver badges105 bronze badges

answered Dec 17, 2010 at 11:28

Aleksei Anufriev's user avatar

Aleksei AnufrievAleksei Anufriev

3,2061 gold badge26 silver badges31 bronze badges

4

Despite the original question being posted five years ago, the problem still persists and is rather annoying.

The general solution is thorough analysis of all referenced assemblies to understand what’s going wrong. To make this task easier I made a tool (a Visual Studio extension) which allows selecting a .NET assembly (a .dll or .exe file) to get a graph of all the referenced assemblies while highlighting conflicting or missing references.

The tool is available in Visual Studio Gallery: https://marketplace.visualstudio.com/vsgallery/051172f3-4b30-4bbc-8da6-d55f70402734

Example of output:
enter image description here

Jeremy Caney's user avatar

Jeremy Caney

7,01563 gold badges48 silver badges76 bronze badges

answered May 29, 2017 at 22:34

Mykola Tarasyuk's user avatar

5

At 99% the Could not load file or assembly or one of its dependencies problem is caused by dependencies! I suggest you follow this steps:

  1. Download Dependency Walker from http://www.dependencywalker.com/

  2. Launch Dependency Walker and open the dll (in my case NativeInterfaces.dll)

  3. You can see one or more dll with the error in red Error opening file…

  1. It means that this dll is missing in your system; in my case the dll name is MSVCR71.DLL

  2. You can download missings dll from google and copy in right path (in my case c:windowssystem32)

  3. At this point, you must register the new dll in the GAC (Global Assembly Cache): open a DOS terminal and write:

     cd WindowsSystem32
     regsvr32 /i msvcr71.dll
    
  4. Restart your application

radbyx's user avatar

radbyx

9,30221 gold badges84 silver badges127 bronze badges

answered May 27, 2016 at 12:47

Stefano Lonati's user avatar

3

Following worked for me.

  • Remove Temporary Files C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Files
  • Close VSTS and Open Again
  • Remove and Add the same DLLs (Note: you add the same matching versions)

answered Mar 22, 2013 at 7:22

Riddhi M.'s user avatar

Riddhi M.Riddhi M.

1952 silver badges9 bronze badges

0

Microsoft Enterprise Library (referenced by .NetTiers) was our problem, which was in turn referencing an older version of Unity. In order to solve the problem we used the following binding redirection in the web.config:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

Alternatively, you may want to just update the Enterprise Library to the latest version.

answered Jul 3, 2012 at 10:03

Rebecca's user avatar

RebeccaRebecca

13.9k10 gold badges95 silver badges135 bronze badges

screenshotIn solution explorer right click on project (not solution), in build tab choose Platform target : «Any CPU».

answered Sep 26, 2016 at 14:12

Engin Aydogdu's user avatar

1

Check the Web.config/App.config file in your project. See if the version numbers are correct.

<bindingRedirect oldVersion="X.X.X.X-X.X.X.X" newVersion="X.X.X.X" />

This worked for me.

answered Apr 7, 2015 at 17:29

Jaseem Abbas's user avatar

Jaseem AbbasJaseem Abbas

5,0085 gold badges47 silver badges72 bronze badges

1

Juntos answer is correct but you should also consider:

For the unity v2.1.505.2 different AssemblyVersion and AssemblyFileVersion attributes are specified:

enter image description here

AssemblyFileVersion is used by the NuGet but CLR does not care about it!
CLR is going to use only AssemblyVersion!

So your redirects should be applied to a version that specified in AssemblyVersion attribute. So 2.1.505.0 should be used

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.505.0" newVersion="2.1.505.0" />
</dependentAssembly>
</assemblyBinding>

See also:
What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

answered Nov 26, 2014 at 11:15

Ievgen's user avatar

IevgenIevgen

4,2507 gold badges75 silver badges124 bronze badges

I also got this terrible error and found a solution for this…

  1. Right Click on the Solution name
  2. Click Clean Solution
  3. Restart Visual Studio
  4. Goto project Properties >> Build
  5. Change Configuration to Release
  6. Start Debugging (F5)

1) , 2)

Right Click on the Solution name

4) , 5)

Change Configuration to Release

Hope this will help you also.

answered Sep 17, 2015 at 18:24

Roshana Pitigala's user avatar

Roshana PitigalaRoshana Pitigala

8,3578 gold badges47 silver badges78 bronze badges

I had the same problem i solved it via the instructions below:

  1. open tools menu and select option
  2. in options, window go to Projects and Solutions/Web Projects
  3. check use the 64bit version of IIS ...

enter image description here

answered Jun 12, 2019 at 8:31

Mohammad Almasi's user avatar

0

  • Goto :Solution -> Package
  • Click on Advanced Tab (Find below the page)
  • Add your dll to additional assemblies(this way we can add external dlls in sharepoint).

Community's user avatar

answered Sep 12, 2013 at 6:26

Vijay Singh's user avatar

1

Not sure if this might help.

Check that the Assembly name and the Default namespace in the Properies in your asemblies match. This resolved my issue which yielded the same error.

zero323's user avatar

zero323

320k101 gold badges952 silver badges932 bronze badges

answered Apr 17, 2012 at 10:27

Sjaan's user avatar

SjaanSjaan

511 silver badge1 bronze badge

1

In my case in the bin folder was a non reference dll called Unity.MVC3 , i tried to search any reference to this in visual studio without success, so my solution was so easy as delete that dll from the bin folder.

answered Jan 5, 2016 at 0:00

Totodile's user avatar

TotodileTotodile

1501 silver badge7 bronze badges

Thanks Riddhi M.
Following worked for me.

Remove Temporary Files C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Files
Close VSTS and Open Again
Remove and Add the same DLLs (Note: you add the same matching versions)

answered Jul 30, 2015 at 13:29

Sridhar Kommana's user avatar

1

You say you have a lot of projects in your solution … well, start with one near the top of the build order. Get that one to build and once you figure it out you can apply the same fix to the rest of them.

Honestly, you probably just need to refresh your reference. It sounds like you either updated your version and didn’t update the references, or it’s a relative path issue if you keep your solution in source control. Just verify your assumptions, and re-add the reference.

answered Dec 17, 2010 at 11:30

Joel Martinez's user avatar

Joel MartinezJoel Martinez

46.7k26 gold badges129 silver badges185 bronze badges

if you are getting this error message by opening an application on you windows xp it mean first you have installed that app due to its not working without net framework 4 and service pack 3 . you installed both and again you are getting this error so you should reinstall that app again but first uninstall from add and remove

if this not work please dont abuse me . i am also a junior

answered Nov 16, 2013 at 8:14

basit durrani's user avatar

Following worked for me.

  • Remove Temporary Files C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Files
    • then right click on Temporary Asp.net Files>properties>security
      and give total control access to IIS and to all user runing my project

answered Mar 6, 2015 at 15:38

onlyme's user avatar

onlymeonlyme

3,7562 gold badges22 silver badges17 bronze badges

This issue happened to me where one of my dependent libraries was compiling a DLL with «Any CPU» when the parent library was expecting a compilation of «x64».

answered Nov 16, 2016 at 17:21

Creamstout10's user avatar

1

I had this today, and in my case the issue was very odd:

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0" newVersion="3.1.0.0" />
  </dependentAssembly>0.

Note the stray characters at the end of the XML — somehow those had been moved from the version number to the end of this block of XML!

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>

Changed to the above and voila! Everything worked again.

answered May 12, 2017 at 9:16

garryp's user avatar

garrypgarryp

5,4711 gold badge29 silver badges40 bronze badges

Tried closing and re-opening VS as suggested but it didn’t work out.

I had to change from MIXED PLATFORMS to ANY CPU.

enter image description here

answered Aug 30, 2021 at 14:58

Bartho Bernsmann's user avatar

Bartho BernsmannBartho Bernsmann

2,4331 gold badge25 silver badges33 bronze badges

0

You have to delete Your appname.dll file from your output folder.
Cleanup Debug and Release folders.
Rebuild and copy to output folder regenerated dll file.

answered May 15, 2013 at 7:44

gucci's user avatar

guccigucci

211 bronze badge

I «Set as Startup Project» the unloaded/unfound library/project.

Then deployed it.

It worked!

I think it couldn’t found the .dll because it was not in the assembly at first.

answered Jul 16, 2013 at 5:08

nirav's user avatar

niravnirav

3733 gold badges7 silver badges20 bronze badges

Another possible cause: make sure you haven’t accidentally given both of the projects the same assembly name in project properties.

answered Dec 21, 2014 at 16:33

nathanchere's user avatar

nathancherenathanchere

7,93815 gold badges65 silver badges85 bronze badges

1

My solution for .NET 4.0, using Enterprise Library 5, was to add a reference to:

Microsoft.Practices.Unity.Interception.dll

answered Jun 5, 2015 at 19:44

Entree's user avatar

EntreeEntree

18.3k38 gold badges159 silver badges242 bronze badges

Look out for conflicting references. Even after a clean and rebuild, conflicting references will still cause a problem. My problem was between AForge and Accord. I removed both of the references, and re-added the references re-choosing the particular reference (particular to my case, just Accord).

answered Mar 25, 2016 at 19:05

user3791372's user avatar

user3791372user3791372

4,3955 gold badges43 silver badges77 bronze badges

In my case, none of the proposed answer worked.

Here is what worked for me:

  1. Remove the reference
  2. Rename the DLL
  3. Import the reference again

The second step was important apparently as it did not work without it.

answered Jun 23, 2016 at 8:38

Nicolas Raoul's user avatar

Nicolas RaoulNicolas Raoul

58.4k58 gold badges221 silver badges370 bronze badges

Try checking if the «Copy to Local» property for the reference is set to true and the specific version is set to true. This is relevant for applications in Visual Studio.

answered Jul 6, 2016 at 15:33

Srinivas Somasundaram's user avatar

Hi friends, in this article, we will be discussing about, how to resolve the below error, when working with CLR assemblies in SQL Server:

An error occurred in the Microsoft .NET Framework while trying to load assembly id… The server may be running out of resources, or the assembly may not be trusted. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: System.IO.FileLoadException: could not load file or assembly …

How to Resolve the Issue

In order to resolve the issues, there is a series of steps that you can try.

Step 1: Check if CLR is Enabled in the SQL Server Instance

The first thing to check, which is quite obvious, is whether CLR is enabled or not, in the specific SQL Server instance.

In order to check this, you just need to run in SSMS the below T-SQL statement:

sp_configure 'clr enabled';
GO

In the “run_value” is set to 1, it means that CLR is indeed enabled.

If it is not enabled and you have the approval to indeed enable it, you can do so, using the below T-SQL statements:

sp_configure 'clr enabled',1;
GO
RECONFIGURE WITH OVERRIDE;
GO

Step 2: Check the CLR Assembly File Path References

The next step, is to check the CLR assemblies that are loaded into the SQL Server instance.

To do so, you need to run the following SELECT T-SQL statement:

SELECT * FROM sys.assembly_files;
GO

Based on the query results, you should make sure that the assemblies listed, are indeed located in the referenced file path.

If a reference assembly file (dll) is missing, then that’s the problem and you need to register again the assembly (step 4a).

Step 3: Check the Loaded Assemblies

The next step, is to check the CLR assemblies that are loaded into the SQL Server instance.

To do so, you need to run the following SELECT T-SQL statement:

SELECT * FROM sys.dm_clr_loaded_assemblies;
GO

If the above query does not return anything, then bingo, you just found the problem!

So, in this case, it means that your CLR assembly is not properly registered and you need to refresh it (step 4b).

Step 4a: Registering the CLR Assembly Again in SQL Server

So, if the issue was identified in Step 2, then it means you need to re-register the specific CLR assembly in SQL Server.

To this, you can run the following T-SQL statement:

--Recommendation: Only use CLR Assemblies with SAFE permissions
CREATE ASSEMBLY [ASSEMBLY_NAME]
FROM 'path to assembly .dll file' 
WITH PERMISSION_SET = [SET THE PERMISSION SET HERE: SAFE, UNSAFE OR EXTERNAL]

Step 4a: Refreshing the CLR Assembly in SQL Server

So, if the issue was identified in Step 3, then it means you need to refresh the specific CLR assembly in SQL Server.

To this, you can run the following T-SQL statement:

ALTER ASSEMBLY [ASSEMBLY_NAME]
FROM 'path to .dll file';
GO

Learn more about SQL Server Development – Enroll to our Course!

Enroll to our online course titled “Essential SQL Server Development Tips for SQL Developers(special limited-time discount included in link) and sharpen your SQL Server database programming skills via a large set of tips on T-SQL and database development techniques. The course, among other, features over than 30 live demonstrations!

Essential SQL Server Development Tips for SQL Developers - Online Course

(Lifetime Access/ Live Demos / Downloadable Resources and more!)

Enroll from $12.99

Featured Online Courses:

  • SQL Server 2022: What’s New – New and Enhanced Features
  • Working with Python on Windows and SQL Server Databases
  • Introduction to Azure Database for MySQL
  • Boost SQL Server Database Performance with In-Memory OLTP
  • Introduction to Azure SQL Database for Beginners
  • Essential SQL Server Administration Tips
  • SQL Server Fundamentals – SQL Database for Beginners
  • Essential SQL Server Development Tips for SQL Developers
  • Introduction to Computer Programming for Beginners
  • .NET Programming for Beginners – Windows Forms with C#
  • SQL Server 2019: What’s New – New and Enhanced Features
  • Entity Framework: Getting Started – Complete Beginners Guide
  • Data Management for Beginners – Main Principles
  • A Guide on How to Start and Monetize a Successful Blog

Read Also:

  • Essential SQL Server Development Tips for SQL Developers (Course Preview)
  • Resolve SQL Server CTE Error – Incorrect syntax near ‘)’.
  • The TempDB System Database in SQL Server
  • SQL Server Installation and Setup Best Practices
  • The feature you are trying to use is on a network resource that is unavailable
  • SQL Server 2016: TempDB Enhancements
  • tempdb growth
  • Introduction to SQL Server Machine Learning Services
  • Essential SQL Server Administration Tips
  • What are SQL Server Statistics and Where are they Stored?
  • Tip of the Week No.1 – SQL Server Always Encrypted
  • Tip of the Week No.3 – TempDB Settings During Installation
  • Tip of the Week No.6 – About SQL Server Temporary Tables
  • Tip of the Week No.19 – What is the Database First Workflow in Entity Framework?
  • Tip of the Week No.20 – SQL Server Surface Area
  • Within Which Context Does SQL Server Access Network Resources?
  • Troubleshooting the File Activation Error in SQL Server

Subscribe to our newsletter and stay up to date!

Subscribe to our YouTube channel (SQLNetHub TV)

Check our eBooks!

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading…

Reference: SQLNetHub.com (https://www.sqlnethub.com)

© SQLNetHub

Artemakis Artemiou

Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 20 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and {essentialDevTips.com}. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Moreover, Artemakis teaches on Udemy, you can check his courses here.

Views: 1,412

Visual Studio logo

Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 20 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and {essentialDevTips.com}. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Moreover, Artemakis teaches on Udemy, you can check his courses here.

Views: 1,412

This post was most recently updated on June 13th, 2022.

2 min read.

This post describes how to fix the “Could not load file or assembly ‘[assemblyname]’ or one of its dependencies. An attempt was made to load a program with an incorrect format.” error. 

The solution described in this post shows you how to resolve the issue when you’re deploying from Visual Studio but get an error somewhat like the above when deploying to IIS or when opening your website after the deployment.

This applies to your local development environment.

Problem

Especially while installing a new dev machine, and building your project for the first time, you may end up getting the following exception:

Could not load file or assembly ‘[assemblyname]’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

No fear, though, as this is usually easily fixed. In quite a few cases, it’s simply a mismatch between architectures and easily changed.

Reason

The latter part of the error message should point you in the right direction. “An attempt was made to load a program with an incorrect format.” That means that the assembly, which was to be loaded, was in an unexpected format. The format, in this case, refers most likely to the 64-bit build of an application being deployed to IIS, which is being run in 32-bits.

Why do I think that’s the case? Well, see – by default, Visual Studio uses a 32-bit version of IIS Express (Internet Information Services Express – the free lightweight web server that ships with some Windows versions and are useful for local development with Visual Studio) for your deployments. And if you’re building your solution in x64, running it in 32-bit IIS Express won’t work.

In case you know what you’re doing, it’s safe and easy to change this, though.

In my case, I was indeed building a 64-bit application. Therefore I also had to change the IIS to run in a 64-bit version. That’s luckily quite easy!

Solution: Change the IIS Express to run in 64b

I’ll explain below, how to do this in 4 simple steps. Like, really simple.

Time needed: 2 minutes.

How to change IIS Express to run in 64-bit mode?

  1. You’ll need to enable 64-bit IIS Express from VS settings

    This is an easy, one-click configuration change, but it is hidden quite deep in the Options. First, open up your Visual Studio.

  2. Navigate to Visual Studio – Tools – Options – Projects and Solutions – Web Projects

    Alternatively, use the search for and write “64 bit”.

  3. Select “Use the 64-bit version of IIS Express for websites and projects”

    This’ll look something like in the picture below:
    How to enable the 64-bit version of IIS Express in Visual Studio 2017
    IIS Express 64-bit version – how to fix the “Could not load file or assembly…” -error

  4. Hit “OK” to save your changes.

    That’s it. 4 (or really more like 3) simple steps!


And you should be golden!

Let me know in the comments -section below whether it worked or not. It sure did for me :)

  • Author
  • Recent Posts

mm

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That’s definitely enough funny buzzwords!), who works as Solutions Architect for Precio Fishbone, building delightful Digital Workplaces.

He’s been a developer from 2004 (starting with PHP and Java), and he’s been working on .NET projects, Azure, Office 365, SharePoint and a lot of other stuff. He’s also Microsoft MVP for Azure.

This is his personal professional (e.g. professional, but definitely personal) blog.

mm

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That’s definitely enough funny buzzwords!), who works as Solutions Architect for Precio Fishbone, building delightful Digital Workplaces.

He’s been a developer from 2004 (starting with PHP and Java), and he’s been working on .NET projects, Azure, Office 365, SharePoint and a lot of other stuff. He’s also Microsoft MVP for Azure.

This is his personal professional (e.g. professional, but definitely personal) blog.

mm

4.7
16
votes

Article Rating

 

Have problems with Visual Studio 2019, where I have created a solution with 2 projects. The start-up project (# 1) has been created with the Console App (.NETCore) as a base. The second project (# 2) is based on the Windows Forms app (.NET
Framework)

Project 1 contains the main logic and calls a procedure in project 2 that will set up a form, take care of specified values ​​and return this via global variables. Both projects do their jobs separately. It is when it comes to the call
that errors occur. The call has been adapted as the initial syntax error occurred which has now been corrected so compilation of the solution is error free and without warnings. When executed, there is an interruption

System.IO.FileNotFoundException:
‘Could not load file or assembly ‘System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′. Det går inte att hitta filen.’

This means that it is not possible to track in the program as I wanted. Of course, there are differences in the two projects’ .NET environments that make up for it, but it is not told how I can get hold of the missing file.

Question 1. Does anyone know how to get the file and how it is then incorporated into the environment?

I am not a VB encoder so that with Objects, classes, methods etc. is not something I have immersed myself in. However, I can do so much that I can make it work as regular calls with arguments and so on.

The call itself is simple in itself and I think I got to that with how to send the information. However, I do not find anywhere the values ​​that the parameters should contain.

Call MYform1.Form1_Load(Mysender, Myargs)

Question 2. Does anyone know how to find which values ​​should be included in the Mysender and Myargs parameters

In the log I find this

‘Project20200727.exe’ (CoreCLR: DefaultDomain): Loaded ‘C:Program FilesdotnetsharedMicrosoft.NETCore.App3.1.6System.Private.CoreLib.dll’.

‘Project20200727.exe’ (CoreCLR: clrhost): Loaded ‘C:UsersjannesourcereposProject20200727binDebugnetcoreapp3.1Project20200727.dll’. Symbols loaded.

‘Project20200727.exe’ (CoreCLR: clrhost): Loaded ‘C:Program FilesdotnetsharedMicrosoft.NETCore.App3.1.6System.Runtime.dll’.

‘Project20200727.exe’ (CoreCLR: clrhost): Loaded ‘C:UsersjannesourcereposProject20200727binDebugnetcoreapp3.1WindowsApp3_20200730.exe’. Symbols loaded.

An unhandled exception of type ‘System.IO.FileNotFoundException’ occurred in Unknown Module.

Could not load file or assembly ‘System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’. Det går inte att hitta filen.

The program ‘[13828] Project20200727.exe’ has exited with code -1 (0xffffffff).

Best regards

Janne

  • Moved by

    Friday, July 31, 2020 2:02 AM

In this guide, we’ll walk you through the process of troubleshooting and fixing the System.BadImageFormatException Could Not Load File or Assembly error. This error usually occurs when there’s an issue with the .NET assembly or a mismatch between assembly references and executing the application.

Table of Contents

  1. Overview of System.BadImageFormatException
  2. Common Causes
  3. Step-by-Step Solution
  4. FAQs
  5. Related Links

Overview of System.BadImageFormatException

System.BadImageFormatException is an exception that occurs when the .NET runtime is unable to load a specific assembly. This can happen due to a variety of reasons, such as an incorrect format or corruption in the assembly file. Resolving the issue typically involves identifying the root cause and making the necessary adjustments.

Common Causes

Here are some common causes for the System.BadImageFormatException Could Not Load File or Assembly error:

  1. Mismatch between the target platform of the assembly and the application
  2. Incorrect version of the assembly being used
  3. Corruption in the assembly file
  4. Incompatible .NET runtime version

Step-by-Step Solution

Follow these steps to troubleshoot and fix the System.BadImageFormatException Could Not Load File or Assembly error:

Step 1: Check the Target Platform

Ensure that the target platform of your assembly and your application matches. For example, if your application is built for x86, the referenced assembly should also be built for x86.

  1. In Visual Studio, right-click on your project and select Properties.
  2. Go to the Build tab and check the Platform target dropdown.
  3. Make sure the target platform matches the platform of the referenced assembly.

Step 2: Verify the Assembly Version

Make sure you’re using the correct version of the assembly. To do this:

  1. Right-click on the referenced assembly in your project and select Properties.
  2. Check the Version property and ensure it matches the expected version.

Step 3: Inspect the Assembly File

Check if the assembly file is corrupted or has an incorrect format.

  1. Open the assembly file with a tool like ILDASM or dotPeek.
  2. If the tool is unable to open the file, it might be corrupted or have an incorrect format. In this case, try obtaining a new copy of the assembly.

Step 4: Check .NET Runtime Version

Ensure that your application is using a compatible .NET runtime version with the referenced assembly.

  1. In Visual Studio, right-click on your project and select Properties.
  2. Go to the Application tab and check the Target framework dropdown.
  3. Make sure the target framework is compatible with the referenced assembly.

FAQs

What is System.BadImageFormatException?

System.BadImageFormatException is an exception that occurs when the .NET runtime is unable to load a specific assembly due to issues such as incorrect format or corruption in the file.

How do I know if the target platform of my assembly matches my application?

In Visual Studio, go to your project properties and check the target platform in the Build tab. Make sure it matches the platform of the referenced assembly.

How do I verify the version of the assembly?

Right-click on the referenced assembly in your project and select Properties. Check the Version property and ensure it matches the expected version.

How can I check if the assembly file is corrupted?

You can use tools like ILDASM or dotPeek to inspect the assembly file. If the tool is unable to open the file, it might be corrupted or have an incorrect format.

How do I know if my .NET runtime version is compatible with the referenced assembly?

In Visual Studio, go to your project properties and check the target framework in the Application tab. Make sure it’s compatible with the referenced assembly.

  1. Understanding System.BadImageFormatException
  2. Troubleshooting .NET Assembly Loading
  3. How to: Use ILDASM
  4. JetBrains dotPeek

Возможно, вам также будет интересно:

  • Ошибка could not load dll prototype2engine dll
  • Ошибка could not load config что делать
  • Ошибка could not get temp directory
  • Ошибка could not instantiate mail function что это
  • Ошибка could not get debug privilege are you admin

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии