rocky
rocky

Reputation: 177

System.PlatformNotSupported exception with service stack

I am trying to run a service stack application, it works fine on my dev machine when deployed on another box, I get System.PlatformNotSupported exception. Stack trace below:

Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Net.HttpListener..ctor() at ServiceStack.Host.HttpListener.HttpListenerBase.Start(IEnumerable`1 urlBases, WaitCallback listenCallback) at ServiceStack.Host.HttpListener.HttpListenerBase.Start(String urlBase) at ExcaliburAppHost.Program.Main(String[] args)

I am trying to build a Restful app with self hosting (with no IIS support on the other box).

var listeningOn = args.Length == 0 ? "http://*:8090/" : args[0]; var appHost = new AppHost() .Init() .Start(listeningOn);

error occurs in AppHost().Start() method

Upvotes: 3

Views: 7382

Answers (4)

haseakash
haseakash

Reputation: 77

Right click on project in vs studio.

Select Manage NuGet Packages

browse Online "System.ServiceController" Package

If Version 9.0.0 or higher is installed, then uninstall it

Now Select Version 8.0.1. And Install it.

I have the same issue. And I ended up downgrading System.ServiceController from v9.0.0 to v8.0.1.

I think in V 9.0.0 there are many restrictions applied.

Upvotes: 0

4e 69 63 6b
4e 69 63 6b

Reputation: 246

For me, I was building a .NET 6 worker service in a Docker container on a Linux host, building a Windows service to run on Windows Server 2016. My csproj file has the following properties set, but I was receiving the same PlatformNotSupportedException as the OP:

    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <OutputType>Exe</OutputType>
    <InvariantGlobalization>true</InvariantGlobalization>
    <PublishSingleFile>false</PublishSingleFile>
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
    <PublishReadyToRun>false</PublishReadyToRun>

I was able to resolve this by specifying the runtime option (-r win-x64) directly to the dotnet publish command in my Dockerfile.

Now the application builds from a Docker container running on a Linux host, but the resulting binaries run fine on the Windows Server 2016 platform.

Upvotes: 3

uzrgm
uzrgm

Reputation: 395

To whom facing with exception "System.PlatformNotSupportedException: ServiceController enables manipulating and accessing Windows services and it is not applicable for other operating systems." - in my case I had to add "System.ServiceProcess.ServiceController" NuGet package to my .net 5 Worker Service project and issue is gone.

Upvotes: 3

mythz
mythz

Reputation: 143409

If you have any unmanaged .dlls e.g. sqlite3.dll you may need to set the Platform Target of your project as x86.

You can also try running the Console App as Administrator / sudo in-case it's a permissions issue.

Upvotes: 5

Related Questions