Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

.net-core

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.

like image 377
Silny ToJa Avatar asked Dec 11 '19 11:12

Silny ToJa


2 Answers

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

GUI in Visual Studio

like image 128
matt_w Avatar answered Nov 04 '22 17:11

matt_w


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

like image 28
Ajith Avatar answered Nov 04 '22 18:11

Ajith