Reputation: 97
I am trying to run a windows console application (.net core) in a container. It is working fine on host but as soon as I run the docker container, it throws this error:
The type initializer for 'MyApp.Utility.SystemEventsHandler' threw an exception.
---> System.Runtime.InteropServices.ExternalException (0x80004005): Failed to create system events window thread.
at Microsoft.Win32.SystemEvents.EnsureSystemEvents(Boolean requireHandle)
at Microsoft.Win32.SystemEvents.add_SessionEnding(SessionEndingEventHandler value)
Docker File
# getting base image
FROM mcr.microsoft.com/dotnet/runtime:3.1
# copy files
COPY app/ app/
# set working directory
WORKDIR app
# entry point
#ENTRYPOINT ["dotnet","MyApp.dll"]
Do I need to install something else too in the container ?
Upvotes: 1
Views: 432
Reputation: 1411
The problem is not that you are running the console app on a windows OS host with docker. The problem is that you are running a linux container (very slim version of a linux OS) and then trying to access windows specific APIs.
As the error states Failed to create system events window thread. at Microsoft.Win32.SystemEvents...
That is why the application is working just fine when you debug it on your windows OS host, but not in a linux container. You will get the same effect if you deploy it to a regular linux host or trying to run it in WSL for example.
One thing that might work is switching to a windows container
, but I don't know how your code looks. To switch to windows container, I think you simply right click the system tray icon for docker desktop and swap. But I've never used windows containers, so I would not know.
PS I hope you are not trying to run a GUI application in docker, that is not supported.
Upvotes: 1