A fatal error occurred. The required library hostfxr.dll could not be found

.Net Core

.Net Core Problem Overview


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.

.Net Core Solutions


Solution 1 - .Net Core

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

GUI in Visual Studio

Solution 2 - .Net Core

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://docs.microsoft.com/en-us/dotnet/core/rid-catalog#windows-rids

Solution 3 - .Net Core

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/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.9-windows-hosting-bundle-installer

Solution 4 - .Net Core

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.

Solution 5 - .Net Core

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.

Solution 6 - .Net Core

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.

Solution 7 - .Net Core

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSilny ToJaView Question on Stackoverflow
Solution 1 - .Net Corematt_wView Answer on Stackoverflow
Solution 2 - .Net CoreAjithView Answer on Stackoverflow
Solution 3 - .Net CoreJPJView Answer on Stackoverflow
Solution 4 - .Net CoreJitender KumarView Answer on Stackoverflow
Solution 5 - .Net CoresidcomView Answer on Stackoverflow
Solution 6 - .Net CoreSauliusView Answer on Stackoverflow
Solution 7 - .Net CoreABHISHEK NView Answer on Stackoverflow