Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Fabric System.BadImageFormatException

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

like image 375
Robert N. Dean Avatar asked Feb 17 '17 21:02

Robert N. Dean


2 Answers

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

like image 116
Roman Marusyk Avatar answered Nov 15 '22 10:11

Roman Marusyk


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.

like image 28
Vaclav Turecek Avatar answered Nov 15 '22 09:11

Vaclav Turecek