28

I have created a new Service Fabric application in Visual Studio 2017 (version 15.7.1) and added a new service using the .Net Core 2.0 Stateful Service template.

When I try to run the service it fails to start correctly and I can see the following exception in the Diagnostic Events:

Description='Replica had multiple failures during open on _Node_0. API call: IStatefulServiceReplica.ChangeRole(P);

Error = System.IO.FileNotFoundException (-2147024894) Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41

3 Answers3

69

I fixed this by installing the Nuget package System.ServiceModel.Primitives:

PM> Install-Package System.ServiceModel.Primitives
RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41
4

An answer which may be useful after a Windows 11 update.

In my case, after an update of Windows 11, the application wasn't working because of this error. I had the error Could not load file or assembly System.ServiceModel, version 3.0.0.0.

After long research, I uninstalled the .net framework and re-installed it and it worked.

For this, I used the programs/Uninstall a program/Add remove windows features.

Unchecked all .net framework cases and click on the Okay button. After the uninstall process, I checked the same cases and click on the Okay button.

Bingo!

Coskun Ozogul
  • 2,389
  • 1
  • 20
  • 32
1

The System.ServiceModel.Primitives has what I think is a rather odd bug. If you are using a DLL with a System.ServiceModel.Primatives dependency, then you must also install it as a reference in the project that is using that DLL. If you do not the DLL will not know where to find it and you get the dreaded "could not load file or assembly..." As Ragtimewilly indicated you can easily add the reference through Nuget. There may be a better way to do this - but adding it through Nuget will do the trick.

Destek
  • 154
  • 1
  • 10