Could not load file or assembly #MyAssembly# or one of its dependencies. An attempt was made to load a program with an incorrect format.


Could not load file or assembly #MyAssembly# or one of its dependencies. An attempt was made to load a program with an incorrect format. - PHIXED

This could be happening due to two reasons.

First. you are trying to build one of the projects within the solution in the wrong way!
Second. If your app is a webapp/XBAP app. then your application pools requires some additional settings.

So how to solve it? well if its the first case, then you will have to configure your solution in the below manner..

  • Right click on your project solution and click on properties. 
  • Expand the Configuration properties and select the Configuration
  • Then specify the platform as ANY CPU or depending on the CPU you are working on.As shown below

Now in the below solution i was referencing a project that was built on x86 architecture, hence i was getting the exception. 





Second case : If you are working on a XBAP app and your application is deployed/ published, then probably you may need to do this 

  • Open  IIS-Manager type inetmgr in run
  • Click on Application Pools






  • Right click on the application pool related to your published application, and select Advanced Settings






  • Set Enable 32-Bit Applications from False to True




This will enable the x86 32 Bit Assemblies (dll) to load in your application pool.

No comments:

Post a Comment