sdk: Cannot run dotnet core WinForms app on .Net 6.0
-
.NET Core Version: 6.0.3
-
Have you experienced this same bug with .NET Framework?: No but not directly comparable.
Problem description: Created a new .Net 6.0 winforms app. Built the published content with:
dotnet publish EmailTracker.sln --configuration Release --runtime win10-x64 --no-build --self-contained false
Deployed via CD server onto server and attempted to run the exe. Error message:

Click through and download the 6.0.3 desktop runtime. If I run the app again, same error. I tried installing the base .net core runtime too but still the same error.
Error in event log:
Message: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet\'.
That file does not exist in that folder but it does exist further down under dotnet/shared/Microsoft.NETCore.App/6.0.3 (and other versioned folders)
Then it says Failed to run as a self-contained app, which is fine because it is not supposed to be self-contained.
Expected behavior: I would expect that it would just work when I run the program with the correct runtime installed. Otherwise a much more specific error message if I’ve done something too stupid because this is show-stopping stuff for a new framework that worked perfectly until I tried to deploy it. Understand all the publish options, the SDK for building and the various project settings is very confusing so I might have got something wrong there.
Minimal repro: This is just an app with a single form and nothing special to deploy but I expect it won’t be easy to recreate otherwise you would see it lots of other places.
Deployment server(s): Windows Server 2016 Datacenter 64 bit.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (10 by maintainers)
@lukos great to hear you found the root cause.
Moving the issue to the SDK as this may be something the SDK needs to fix or (better) document.
Thanks @Olina-Zhang I’ve just found out what wasn’t working.
I was passing
--no-buildtodotnet publishbecause we have already run dotnet build and run automated tests so it seemed pointless to build it again as part of publish. I removed that flag and now it works.I’m not sure if that is strictly a bug but is definitely a gotcha (I have 20 years .Net programming so I’m not a noob) but not sure how this could work differently because in other places (not Winforms) we do it this way and it’s fine. Maybe
--self-contained falseshould override no-build or something?