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

问题


When i run my WPF application on other computer it throw me that error.

Description: A .NET Core application failed.
Application: SamplerSLEX.exe
Path: C:\Users\admin\Downloads\TesterSLEX\TesterSLEX\SamplerSLEX.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:\Users\admin\Downloads\TesterSLEX\TesterSLEX\].
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.

WPF netcoreapp3.0


回答1:


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




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/59284895/a-fatal-error-occurred-the-required-library-hostfxr-dll-could-not-be-found

标签

更多相关内容:请点击查看