Showing posts with label .DLL files. Show all posts
Showing posts with label .DLL files. Show all posts

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.

Adding a DLL to the Global Assembly Cache(GAC)


 Adding a DLL to the Global Assembly Cache(GAC)
Open the visual studio command prompt in administrative mode as shown below and navigate to the directory containing the .dll file (class library file) that is built.

 Navigate to the directory that contains the .dll file as shown below and type the command: gacutil /i followed by the name of the .dll file. here in the command the i stands for install. you can use the /u  to uninstall a dll from the GAC.
To navigate to the directory use the “cd” command in the command line 
for example:
Cd D:\Enlistment\Dax6HFSTABVMS\source\Application\VMSModel\Visual Studio Projects\C Sharp Projects\VMSRegressionBugDetails\bin\Debug
Command to add the assembly to the global assembly cache will be similar to this:
gacutil /i VMSRegressionBugDetails.dll

Click on the image to enlarge
 Press enter and the following screen will be displayed with the message saying
 “Assembly successfully added to cache”.
                                                          Click on the image to enlarge
 The dll is now added to the Global Assembly Cache.
This was successfully tested for a dll that was added to the GAC for the use in Dynamics Ax environment.