BadImageFormatException on Microsoft.TeamFoundation.Client.dll
Hello,
I am just starting to work with the Team Foundation SDK and have added references to the Microsoft.TeamFoundation.dll, Microsoft.TeamFoundation.Client.dll and Microsoft.TeamFoundation.WorkItemTracking.Client.dll. I've written some simple code to create an instance of the TeamFoundationServer class. The app builds and executes, but when I step in the debugger into the function to instantiate the TeamFoundationServer I get the following exception:
System.BadImageFormatException: Could not load file or assembly 'Microsoft.TeamFoundation.Client, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'Microsoft.TeamFoundation.Client, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Has anyone else had this problem? I asked a colleage to send his M.TF.C.dll so I could try that and I get the same issue. The DLL looks like a good PE image. Version properties display fine in the Shell. Does anybody have any thoughts on this?
Thanks,
Dan
And a quick followup: I have opened the Microsoft.TeamFoundation.Client.dll in Lutz Roeder's .NET Reflector and it happily lets me browse the objects and code of the dll.... I guess that should indicate to me that the DLL itself is fine, but a dependency may be corrupt? I opened MTFC.dll in Dependency Walker and it looks good - only dependency is MSCOREE.dll and it is being loaded by DW. In .NET Reflector, I see that CREDUI.DLL is a DLLImport of MTFC.dll, but I have that in my System32. Dependency Walker doesn't have anything negative to say about CredUI.dll either...
Oh, and I am using WinXP 64-bit... I noticed that I have two CredUI.dlls. One in System32, one in SysWOW64. Maybe the CLR cares which CREDUI.DLL it loads?
Ok, I haven't solved the problem yet, but... I just tested my app on a WinXP 32-bit machine and it ran without issue - so I guess the issue is with WinXP 64-bit and maybe the CredUI.DLL that the Microsoft.TeamFoundation.Client.dll wants to load. If I figure out how to work around this I'll post some details as a followup.
Still no luck. I copied the CredUI.dll from my SysWOW64 directory, as well as all it's direct depenencies, into the test apps Debug directory, but this didn't change the error at all. Still BadImageFormatException....
Successful workaround! In the Project Settings for my project, on the Build tab their is a settings named "Platform target". It defaults to Any CPU. After changing it to "x86", my application runs (both in the debugger, and from the command line) as expected and properly loads the Microsoft.TeamFoundation.Client.dll.