6
votes

I downloaded the latest version of Service Fabric SDK 2.4.164 and try to create a new simple stateless service. Build succeeded but when I run it to debug I got:

An unhandled exception of type 'System.BadImageFormatException' occurred in Unknown Module.

Additional information: Could not load file or assembly 'System.Fabric, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. An attempt was made to load a program with an incorrect format.

What is the problem? Please help to solve that. Let me know if I have to add more informations

2
You're x86 and the DLL is x64, or vice versa.user1228
Thanks, but how can I fix that? What is that dlls?Robert N. Dean

2 Answers

7
votes

Azure Service Fabri only supports x64 platform. It seems you're using some x86 tools. If you have installed dotnet (CLI) tools for x64 and x86 then check Path environment variable. The first one should be path to the x64 components, it helped me to solve the same issue enter image description here

6
votes

All Service Fabric assemblies are compiled to x64. Make sure your project is also targeting x64, and not AnyCPU.

The best way to do this is to go into Configuration Manager in Visual Studio, create x64 build configurations for each project, and then delete all of the AnyCPU build configurations. That's how the Service Fabric project templates in Visual Studio are set up. But if you create a project from a different template, like Console Application or Class Library, it will be created with an AnyCPU build configuration - you need to change that to x64 if you reference any Service Fabric assemblies.