SharpeRAD/Cake.Services

Missing System.ServiceProcess assembly reference when trying to use with Cake.IIS

Closed this issue · 7 comments

Hi!

I tried to use Cake.Services and Cake.IIS addins at the same time and got the following error:

Error: Error occurred when compiling build script: (2469,30): error CS1069: The type name 'ServiceController' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2475,30): error CS1069: The type name 'ServiceController' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2481,30): error CS1069: The type name 'ServiceControllerStatus' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2487,30): error CS1069: The type name 'ServiceControllerStatus' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.

Here is my build.cake:

#addin "Cake.Services"
#addin "Cake.IIS"

Task("Default")
  .Does(() =>
{
  Information("YEY");
});

RunTarget("Default");

Each addin works correctly when used alone, but when both of them are referenced the error occurs.

The only workaround I've found so far is to add missing assembly using the #reference directive: #reference System.ServiceProcess.

Can you fix this issue if it is possible. If not then hopefully this info can help someone to save some time.

Sorry I can't reproduce this error using your example and to be honest the line numbers don't make sense as the scripts not that long (2469) so I don't think that script generated that error. Cake.IIS doesn't reference System.ServiceProcess so I can't see how the two could conflict.

I think your using classes from System.ServiceProcess in your build script like this:
ServiceController controller = GetService("MpsSvc");
which works for me without the need for a reference directive.

I don't know why line numbers are so long. The cake script I used is exactly the same as in the example above. And I'm absolutely sure that I didn't use anything from System.ServiceProcess in my build.cake file.
I can make a video with steps that can be used to reproduce this issue starting from an empty folder if it will be helpful.

What OS are you running it on?

See if you get the same issue with v0.3.1 as I added a framework reference for "System.ServiceProcess" to the nuget package which could help.

My OS is Windows 10 Enterprise x64.

With v0.3.1 error message changed to

Error: Error occurred when compiling build script: (2469,30): error CS1069: The type name 'ServiceController' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2475,30): error CS1069: The type name 'ServiceController' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2481,62): error CS1069: The type name 'ServiceController' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2487,62): error CS1069: The type name 'ServiceController' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2493,30): error CS1069: The type name 'ServiceControllerStatus' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2499,30): error CS1069: The type name 'ServiceControllerStatus' could not be found in the namespace 'System.ServiceProcess'. This type has been forwarded to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
(2483,12): error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<System.ServiceProcess.ServiceController>' to 'System.Collections.Generic.List<System.ServiceProcess.ServiceController>'
(2489,12): error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<System.ServiceProcess.ServiceController>' to 'System.Collections.Generic.List<System.ServiceProcess.ServiceController>'

Tried to create binding redirect in Cake.exe.config file with no luck. But I was managed to find out which assemblies use different versions of the System.ServiceProcess assembly.

  • The 4.0.0.0 version is referenced by the System.ServiceProcess.ServiceController which is used in the Cake.Services add-in.
  • The 2.0.0.0 version is referenced by the Microsoft.Web.Administration which is used in the Cake.IIS add-in.

So, the Cake.Services add-in already uses the v4.0.0.0 assembly and that is why the above fix didn't help.

I hope the above information will help you to find the core reason of this issue.

Try again with v0.3.2

Having the same issue in v0.3.2
@KoshelevS do you find out a solution?

@SharpeRAD
Similar error on this simple script

#addin "Cake.IIS"
StopPool("DefaultAppPool");
Could not load file or assembly 'System.ServiceProcess.ServiceController, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The system cannot find the file specified.

Windows 7 x64 Pro; Cake.IIS 0.3.3