Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0' exception when starting Stateful Service

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.

like image 349
RagtimeWilly Avatar asked Jun 06 '18 23:06

RagtimeWilly


2 Answers

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

PM> Install-Package System.ServiceModel.Primitives
like image 153
RagtimeWilly Avatar answered Nov 14 '22 17:11

RagtimeWilly


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!

like image 3
Coskun Ozogul Avatar answered Nov 14 '22 18:11

Coskun Ozogul