AdsServer Connect System.PlatformNotSupportedException: ServiceController enables manipulating and accessing Windows services and it is not applicable for other operating systems
Hi, i got the following exception message when i tried to start the AdsServer
[ERROR] AdsServer Connect System.PlatformNotSupportedException: ServiceController enables manipulating and accessing Windows services and it is not applicable for other operating systems. at System.ServiceProcess.ServiceController..ctor(String name) at TwinCAT.Ads.Server.AmsServer.isTwinCATServiceRunning() at TwinCAT.Ads.Server.AmsServer.CheckPInvokeAvailable(ILogger logger) at TwinCAT.Ads.Server.AmsServer.createRouterSocketImplementation(ChannelPortType requestedPortType) at TwinCAT.Ads.Server.AmsServer.createServerImplementation(ChannelProtocol requestedProtocol, ChannelPortType requestedPortType) at TwinCAT.Ads.Server.AmsServer.ConnectServerAndWaitAsync(CancellationToken cancel) at TwinCAT.Ads.Server.AdsServer.ConnectServerAndWaitAsync(CancellationToken cancel)
Test setup
- Windows 11
- Beckhoff.TwinCAT.Ads 6.2.347
- AdsServer runs in a .NET Core 8 application
Error has only occurred once so far and could not be readjusted. Restarting the application solved the problem!
Interesting. I have no explanation for that. The method isTwinCATServiceRunning checks, if the code is running on a Windows System before it accesses the ServiceController. So the PlatformNotSupportedException doesn't make sense ... Please post here in case it happens again.
Please reopen in case this happens again
I got this error three times today. It always happened after starting the application following a computer restart. When starting the application, it cannot be guaranteed that the TwinCat system service has already been fully booted up. Could this be related in some way? I don't get this error on other computers.
Ok, as part of a Windows restart this could make sense (your application is started before TwinCAT finishes booting up). The PlatformNotSupportedException seems to be misleading. I will have a look into it to find out how to prevent this 'race-condition'
The error was resolved by adding a dependency to the service "TwinCat3 System Service"
The problem is probably that the service that sets up the AdsServer starts earlier than the TwinCAT3 system service.
Nevertheless, a solution without dependency would be advantageous here.