TF6000_ADS_DOTNET_V5_Samples icon indicating copy to clipboard operation
TF6000_ADS_DOTNET_V5_Samples copied to clipboard

AdsServer Connect System.PlatformNotSupportedException: ServiceController enables manipulating and accessing Windows services and it is not applicable for other operating systems

Open Stiwa-PohG opened this issue 5 months ago • 5 comments

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!

Stiwa-PohG avatar Jul 23 '25 08:07 Stiwa-PohG

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.

RalfHeitmann avatar Jul 24 '25 14:07 RalfHeitmann

Please reopen in case this happens again

RalfHeitmann avatar Sep 05 '25 15:09 RalfHeitmann

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.

Stiwa-PohG avatar Sep 10 '25 05:09 Stiwa-PohG

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'

RalfHeitmann avatar Sep 10 '25 06:09 RalfHeitmann

The error was resolved by adding a dependency to the service "TwinCat3 System Service"

Image

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.

Stiwa-PohG avatar Sep 10 '25 12:09 Stiwa-PohG