Loading 32-bit plugin fails with BadImageFormatException

Issue

[powerGateServer.Core.PluginFramework.PluginManager] - Failed to load plugin: Some32BitPlugin
System.BadImageFormatException: Could not load file or assembly 'Some32BitPlugin.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
Filename: "Plugin32Bit.dll"
at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
at System.Reflection.Assembly.LoadFile(String path)
at powerGateServer.Core.PluginFramework.AssemblyPlugin.�()
at powerGateServer.Core.PluginFramework.AssemblyPlugin.�()
at powerGateServer.Core.PluginFramework.AssemblyPlugin.LoadImpl()
at powerGateServer.Core.PluginFramework.Plugin.Load()
at powerGateServer.Core.PluginFramework.PluginManager.TryLoadPlugin(Plugin plugin)
  • When the plugin is build with AnyCPU but it references some x86 third party assembly the plugin gets loaded but requests to the custom services fail with following response:
{
"error": {
"code": "",
"message": {
"lang": "en-US",
"value": "Internal Server Error! Could not load file or assembly \"file:///C:\\ProgramData\\coolOrange\\powerGateServer\\Plugins\\HelloWorldPlugin\\SomeThirdParty32BitAssembly.dll\" or one of its dependencies. An attempt was made to load a program with an incorrect format."
},
"innererror": {
"message": "Could not load file or assembly \"file:///C:\\ProgramData\\coolOrange\\powerGateServer\\Plugins\\HelloWorldPlugin\\SomeThirdParty32BitAssembly.dll\" or one of its dependencies. An attempt was made to load a program with an incorrect format.",
"type": "System.BadImageFormatException",
"stacktrace": " at Plugin32Bit.Entities.Developer..ctor()\r\n at Plugin32Bit.Developers.Query(IExpression`1 expression) in c:\\Users\\coolOrange\\Documents\\Visual Studio 2012\\Projects\\HelloWorldPlugin\HelloWorld\\HelloWorldServices.cs:Zeile 11.\r\n at powerGateServer.Core.WcfFramework.Internal.QueryProviderSdkAdapter`1.Execute(Expression expression)"
}
}
}

Cause

The BadImageFormatException is thrown because powerGateServer is running as 64-bit processes, but the plugin itself (or a referenced assembly) targets the platform x86 instead!

It is not possible to use 32-bit assemblies in 64-bit processes or vice versa.

Solution

To be able to still use the plugin there are multiple possibilities:

  • Make sure to set the Platform target property in the Visual Studio project of the plugin to AnyCPU and recompile it.
  • Use a AnyCPU or 64-bit version of the referenced assemblies.

            Contact the third party assembly provider and recompile your plugin using the AnyCPU or x64 version of the references.

  • Contact support@coolorange.com for a 32-bit version of powerGateServer that can be installed on a 64-bit and 32-bit Windows environments.

            Please keep in mind that the 32-bit version is not tested and not supported!

See Also