PLUGIN REGISTRATION TOOL ‘Unhandled Exception: System.BadImageFormatException: Could not load file or assembly’

Running Visual Studio 2010 within Windows 7 64 bits I experienced this exception while trying to register an assembly into Dynamics CRM 4.

image

Error text:

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. An attempt was made to load a program with an incorrect format.

at System.Reflection.Assembly._GetExportedTypes()

at PluginRegistrationTool.AssemblyReader.RetrievePluginsFromAssembly(String path) in D:\pablop\Documents\DynamicsCRM\SDK\sdk13\sdk\tools\pluginregistration\AssemblyReader.cs:line 59

at PluginRegistrationTool.AssemblyReader.RetrievePluginsFromAssembly(String path)

at PluginRegistrationTool.RegistrationHelper.RetrievePluginsFromAssembly(String pathToAssembly) in D:\pablop\Documents\DynamicsCRM\SDK\sdk13\sdk\tools\pluginregistration\RegistrationHelper.cs:line 49

at PluginRegistrationTool.PluginRegistrationForm.btnLoadAssembly_Click(Object sender, EventArgs e) in D:\pablop\Documents\DynamicsCRM\SDK\sdk13\sdk\tools\pluginregistration\PluginRegistrationForm.cs:line 127

CAUSE

I found that the cause of the problem came from working with 64 bits. Honestly, not sure if it was due to my plugin assembly was written using 64 bits and the Plugin Registration Tool was compiled in 32 bits or vice versa.

Anyway…

THE SOLUTION

The solution I found was explicitly set ‘Platform Target’  = x86 both for Plugin Registration Tool and the plugin assembly project.

So, open the source code of the tool, located at the \tools\pluginregistration folder within Dynamics CRM SDK.

Right click on ‘Properties’ , click ‘Open’, go to ‘Build’ tab and select Platform Target to x86.

image

Repeat the same for your plugin project.

Then, run the tool again and try to register the assembly again.

It should work like a charm now Smile

clip_image001

clip_image002

clip_image003

Hope it helps to save somebody else time.

PP



1 Comment

Comments have been disabled for this content.