question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot run dotnet core WinForms app on .Net 6.0

See original GitHub issue
  • .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:

image

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
RussKiecommented, Mar 23, 2022

@lukos great to hear you found the root cause.

I was passing --no-build to dotnet publish because 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 false should override no-build or something?

Moving the issue to the SDK as this may be something the SDK needs to fix or (better) document.

2reactions
lukoscommented, Mar 23, 2022

Thanks @Olina-Zhang I’ve just found out what wasn’t working.

I was passing --no-build to dotnet publish because 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 false should override no-build or something?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to target .NET 6.0 with Visual Studio 2019?
Hello: I know .NET 6.0 is released, but I don't know how to create a WinForm App targeting .NET 6.0 with Visual Studio...
Read more >
visual studio - .NET 6.0 not listed in VS2022 (17.1.3)
As far as I know VS2022 should support dotnet 6.0 framework and make it easily targetable... But for some reason VS2022 doesn't have...
Read more >
"You must install .NET Desktop Runtime 6.0.4 (x64)" error
When I try running the binaries on a Windows 10 machine, I get the following message box: To run this application, you must...
Read more >
Is there any way to run a .NET Core WinForms app on Mono?
NET Core, but I'm concerned that it will be no longer possible to run them on Linux since from what little I can...
Read more >
.NET core vs .NET framework
NET Core is used to create server applications that run on Windows, Linux and Mac. It does not currently support creating desktop applications...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found