Skip to content

ServiceManager bypasses injected IWin32ErrorProvider in two methods #295

@Christophe-Rogiers

Description

@Christophe-Rogiers

Description

In src/Servy.Core/Services/ServiceManager.cs, the class injects IWin32ErrorProvider _win32ErrorProvider and uses it consistently in most methods (lines 122, 146, 183, 305). However, two methods bypass the abstraction and call Marshal.GetLastWin32Error() directly:

Line 511InstallServiceAsync:

int error = Marshal.GetLastWin32Error();

Line 829GetAllServices:

throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to open Service Control Manager.");

This breaks the testability contract — unit tests that mock IWin32ErrorProvider cannot control behavior in these two methods.

Severity

Warning — bypasses the injected abstraction, breaks testability.

Suggested fix

Replace Marshal.GetLastWin32Error() with _win32ErrorProvider.GetLastWin32Error() in both locations.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions