2

I am looking to use the System.ServiceProcess.ServiceController class in a .NET Standard 2.0 project. In order to do so I downloaded the Microsoft.Windows.Compatibility packet from NuGet, whic includes among other things ( I also tried to simply download the System.ServiceProcess.ServiceController packet by itself). I can now use the ServiceController without any problem within my class, but when I try to run the program I get:

System.IO.FileNotFoundException: Could not load file or assembly 'System.ServiceProcess.ServiceController, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I guess I'm missing something crucial here, especially since as far as I can tell the version I installed is 4.5.0 and the version it is looking for is the 4.2.1.0. What am I doing wrong?

Nicolo Castro
  • 195
  • 1
  • 3
  • 8
  • 1
    install this NuGet package in the project: https://www.nuget.org/packages/System.ServiceProcess.ServiceController/ and edit runtime bindings in app.config – magicandre1981 Sep 11 '18 at 14:36
  • That is the project I had initially installed (I guess the Compatibility package is simply a collection of individual packages). For the bindings, since I am using .NET Standard I found here: https://stackoverflow.com/questions/46111749/adding-a-bindingredirect-to-a-net-standard-library that the way to go was to add to true in the .csproj file, but it still gives me the same error. Should I create an app.config to the project as well? How should I add the binding? – Nicolo Castro Sep 11 '18 at 15:19
  • add a app.config and [add this](https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element) for System.ServiceProcess.ServiceController to redirect 4.2.1.0 to 4.5 – magicandre1981 Sep 12 '18 at 15:19
  • @magicandre1981 There shouldn't need to be an app.config in a .NET Standard library. The entire point is it's a library, not an application. – willwolfram18 Sep 30 '18 at 06:09
  • 1
    Ok so it took me a while because I had to work on another project... the answer was rather simple in the end, the .NET Standart project was actually referenced from a .Net Framework project. The .Net Framework had the v4.2.1 automatically loaded while the .NET Standard had the v4.5 due to the compatibility package. So i installed the compatibility package on the .Net Framework and it all worked out – Nicolo Castro Nov 28 '18 at 16:38

0 Answers0