Skip to content

Correcting an Exception When Loading Program

Load From Exception: "An attempt was made to load a program with an incorrect format."

While trying to load an assembly into PowerShell recently, an exception occurred,

"Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly ‘file:///…’ or one of its dependencies. An attempt was made to load a program with an incorrect format."

The cause of the problem was a mismatch in the platform target of the assembly. The assembly targets "x86" for example, rather than "Any CPU" or "x64" – the latter is the default PowerShell platform on Windows 8+ and Windows 2012+.

To correct the problem you either need to recompile the assembly using a more appropriate platform target (see the Visual Studio project’s property Build tab) or you need to run the 32-bit version of PowerShell:


or, for ISE:


Windows 8+ runs the x64 version of PowerShell by default when launched from the Windows Menu and doesn’t even show an x86 icon. To correct this, you need to show the Administrative Tools.

3 thoughts on “Correcting an Exception When Loading Program”

  1. I get the same error when I try to run the powershell script with admin rights by 64 bit powershell on a windows 10 machine. I need to query and enable WindowsOptionalFeatures which requires elevated rights (admin). This command will not work on a 32 bit powershell. But when executed powershell from NSIS i get this error. I don’t know the correct way of calling the powershell from NSIS to get this working. Please help me out. Thanks!

  2. Thanks a ton for this. Was tearing out my hair trying to figure out why my Powershell script seemingly suddingly stopped working.

Leave a Reply

Your email address will not be published. Required fields are marked *