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

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.

1

7 Answers

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

GUI in Visual Studio

5

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

1

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.

1

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.

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

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.

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.

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like