78

When I run my WPF application on other computers it throws me this error:

Description: A .NET Core application failed.
Application: program.exe
Path: C:\fakepath\program.exe
Message: A fatal error occurred. The required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in 
[C:\fakepath\].
If this is a framework-dependent application, install the runtime in the global location [C:\Program 
Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or 
register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation].

Add library runtime 3.1.0 it help me.

Silny ToJa
  • 1,815
  • 1
  • 6
  • 20
  • I had this issue with test project on Azure. I had to add a step to install runtime at the beginning of a pipeline. – Lukas Dvorak Oct 24 '20 at 12:41

7 Answers7

85

Further to Ajith's answer, "Deployment Mode: Self Contained" can also be selected in Visual Studio 2019 here:

GUI in Visual Studio

matt_w
  • 1,096
  • 8
  • 8
  • Doing this throws ´System.PlatformNotSupportedException´ in my case – Adan Sandoval Jan 08 '21 at 16:18
  • I need to run console application exe another windows 10 machine which was not exist .net framework which was published in VS 2019. But I couldn't run it. same error occurred. What should I do?AdanSandoval – Lasal Senarath Jan 31 '21 at 17:37
  • 4
    Self contained, oddly enough, didn't fix it for me by itself. If you click Show all settings -> File publish options, I had to also check "Produce Single File" and "Enable ReadyToRun compilation" and then it worked. – Dan Csharpster Aug 31 '21 at 14:19
  • @DanCsharpster - Yes, that did the trick for me, too. But - it created 60 MB exe file for my 30 line console app. I was building my other little console apps in Visual Studio 2008 until now, and just grabbing a few KBs files. This is quite a surprise ... – Marek Sep 03 '21 at 12:22
  • @Marek, its putting all of the libraries you might possibly need to run it into one file. That didn't quite surprise me, but it was annoying. – Dan Csharpster Sep 06 '21 at 18:20
31

I got the same error for my .Net core 3.0 app today. This is because you are missing the .net core run time in the machine, and is installing a framework dependent application.

The solution for this is to publish the application with Deployment Mode Self Contained.

Use the below command to publish from command line

dotnet publish -c Release -r <RID> --self-contained true

get the RID details from https://learn.microsoft.com/en-us/dotnet/core/rid-catalog#windows-rids

Ajith
  • 1,447
  • 2
  • 17
  • 31
  • 3
    I am building my program with `msbuild` instead of `dotnet publish` do you happen to know the flag to turn on Deployment Mode Self Contained? – G. Maniatis Aug 21 '20 at 02:42
19

My solution to avoid "hostfxr.dll missing" in a framework-dependent application was to install the the "Hosting Bundle" on the target computer.

The ASP.NET Core Runtime enables you to run existing web/server applications. On Windows, we recommended installing the Hosting Bundle, which includes the .NET Core Runtime and IIS support.

https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.12-windows-hosting-bundle-installer

testing_22
  • 2,340
  • 1
  • 12
  • 28
JPJ
  • 199
  • 1
  • 2
6

As from the error message, if this is a framework-dependent application :

If this is a framework-dependent application, install the runtime in the global location [C:\Program 
Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or 
register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation].

Please set the DOTNET_ROOT environment to one of the following locations, depending upon where you have installed dotnet.exe

C:\Program Files\dotnet OR C:\Program Files (x86)\dotnet

from "My Computer | Properties | Advanced | Environment Variables". Now restart your IDE/Terminal whatever you are using.

Jitender Kumar
  • 2,439
  • 4
  • 29
  • 43
  • I have wasted a week of evenings trying to work out issue where NUnit was not working, wish I could give you 10 votes. Nunit and .NET Core working now –  Jan 10 '21 at 10:28
3

For some weird reason .net publisher failed to publish self-contained .Net Core 3 application (console app). I've solved this just installing .Net Core 3 Runtime on the server.

Saulius
  • 1,736
  • 20
  • 29
1

I ended up on this page many times in my search for a solution to my problem.

My self contained exe was raising the error

Could not load file or assembly 'System.Data.SqlClient, Version=4.6.1.1

I was publishing the .net core 3.1 runtime and referencing a netstandard library that referenced System.Data.SqlClient, Version=4.6.1.1

The following git hub page has this marked as a known issue https://github.com/dotnet/core/blob/master/release-notes/3.1/3.1-known-issues.md#net-core-312

Setting our exe to publish the .net core 3.0 runtime fixed this for us. We have control of the referenced library so will probably follow the advice on the github page but for anyone else that has not got control of library may find this of use.

sidcom
  • 111
  • 1
  • 8
0

EntityFrameWork Core has been moved out of the dotnet sdk you need to install dependency globally check progr C:\Users"Your User Name".dotnet\tools.store\dotnet-ef\3.1.5 if it was present you have sucessfully installed EFcore globally and make sure your project level Ef Core dependency version matching with globally installed EFcore version .....if there is a mismatch it will trow above error...if you uninstalled make sure you are deleting the above path folder C:\Users"Your User Name".dotnet\ and again reinstalling....It will Worked for me

ABHISHEK N
  • 29
  • 3