Skip to content

PlatformNotSupportedException when running Mage in Nano Server #213

@mthalman

Description

@mthalman

When attempting to run dotnet mage in a Windows Nano Server container, I get the following error:

Unhandled exception. System.PlatformNotSupportedException: The system does not support the STA thread apartment.

Repro steps using a Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0-nanoserver-1809

RUN dotnet tool install -g Microsoft.DotNet.Mage
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\Users\ContainerUser\.dotnet\tools"
USER ContainerUser

RUN dotnet mage
C:\> docker build .
Sending build context to Docker daemon  397.3kB
Step 1/6 : FROM mcr.microsoft.com/dotnet/sdk:6.0-nanoserver-1809
 ---> f39bade63efb
Step 2/6 : RUN dotnet tool install -g Microsoft.DotNet.Mage
 ---> Running in 89b85a1c96dc
Tools directory 'C:\Users\ContainerUser\.dotnet\tools' is not currently on the PATH environment variable.

You can add the directory to the PATH by running the following command:

setx PATH "%PATH%;C:\Users\ContainerUser\.dotnet\tools"

You can invoke the tool using the following command: dotnet-mage
Tool 'microsoft.dotnet.mage' (version '6.0.1') was successfully installed.
Removing intermediate container 89b85a1c96dc
 ---> bab0558ccbcc
Step 3/6 : USER ContainerAdministrator
 ---> Running in 6518834e2c22
Removing intermediate container 6518834e2c22
 ---> a56467f01626
Step 4/6 : RUN setx /M PATH "%PATH%;C:\Users\ContainerUser\.dotnet\tools"
 ---> Running in 15eea996c79e

SUCCESS: Specified value was saved.
Removing intermediate container 15eea996c79e
 ---> 0dea20a3d3a0
Step 5/6 : USER ContainerUser
 ---> Running in 1ee97a3a81ab
Removing intermediate container 1ee97a3a81ab
 ---> 9270aa52c7e8
Step 6/6 : RUN dotnet mage
 ---> Running in 480e4fe8d91a
Unhandled exception. System.PlatformNotSupportedException: The system does not support the STA thread apartment.
The command 'cmd /S /C dotnet mage' returned a non-zero code: 3762504530

This occurs because Nano Server doesn't support single threaded apartments.

A similar issue had occurred with F# Interactive. See their solution for reference: dotnet/fsharp#10122

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions