Troubleshoot .NET errors related to missing files on Linux
When you try to use .NET on Linux, commands such as dotnet new
and dotnet run
may fail with a message related to a file not being found, such as fxr, libhostfxr.so, or FrameworkList.xml. Some of the error messages may be similar to the following items:
System.IO.FileNotFoundException
System.IO.FileNotFoundException: Could not find file '/usr/share/dotnet/packs/Microsoft.NETCore.App.Ref/5.0.0/data/FrameworkList.xml'.
A fatal error occurred.
A fatal error occurred. The required library libhostfxr.so could not be found.
or
A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist.
or
A fatal error occurred, the folder [/usr/share/dotnet/host/fxr] does not contain any version-numbered child folders.
Generic messages about dotnet not found
A general message may appear that indicates the SDK isn't found, or that the package has already been installed.
One symptom of these problems is that both the /usr/lib64/dotnet
and /usr/share/dotnet
folders are on your system.
Tip
Use the dotnet --info
command to list which SDKs and Runtimes are installed. For more information, see How to check that .NET is already installed.
What's going on
Important
Starting with .NET 9, Microsoft only publishes packages for supported Linux distributions that don't publish their own packages. For more information, see Install .NET on Linux.
These errors usually occur when two Linux package repositories provide .NET packages. While Microsoft provides a Linux package repository to source .NET packages, some Linux distributions also provide .NET packages. These distributions include:
- Alpine Linux
- Arch
- CentOS Stream
- Fedora
- RHEL
- Ubuntu 22.04+
If you mix .NET packages from two different sources, you'll likely run into problems. The packages might place things at different paths and might be compiled differently.
Solutions
The solution to these problems is to use .NET from one package repository. Which repository to pick, and how to do it, varies by use-case and the Linux distribution.
- My Linux distribution provides .NET packages, and I want to use them.
- I need a version of .NET that isn't provided by my Linux distribution.
My Linux distribution provides .NET packages, and I want to use them
Do you use the Microsoft repository for other packages, such as PowerShell and MSSQL?
Yes
Configure your package manager to ignore the .NET packages from the Microsoft repository. It's possible that you've installed .NET from both repositories, so you want to choose one or the other.
Remove the existing .NET packages from your distribution. You want to start over and ensure that you don't install them from the wrong repository.
sudo dnf remove 'dotnet*' 'aspnet*' 'netstandard*'
Configure the Microsoft repository to ignore .NET packages.
echo 'excludepkgs=dotnet*,aspnet*,netstandard*' | sudo tee -a /etc/yum.repos.d/microsoft-prod.repo
Reinstall .NET from the distribution's package feed. For more information, see Install .NET on Linux.
No
Remove the existing .NET packages from your distribution. You want to start over and ensure that you don't install them from the wrong repository.
sudo dnf remove 'dotnet*' 'aspnet*' 'netstandard*'
Delete the Microsoft repository feed from your distribution.
sudo dnf remove packages-microsoft-prod
Reinstall .NET from the distribution's package feed. For more information, see Install .NET on Linux.
Do you use the Microsoft repository for other packages, such as PowerShell and MSSQL?
Yes
Configure your package manager to ignore the .NET packages from the Microsoft repository. It's possible that you've installed .NET from both repositories, so you want to choose one or the other.
Remove the existing .NET packages from your distribution. You want to start over and ensure that you don't install them from the wrong repository.
sudo apt remove 'dotnet*' 'aspnet*' 'netstandard*'
Create
/etc/apt/preferences
, if it doesn't already exist.touch /etc/apt/preferences
Open
/etc/apt/preferences
in an editor and add the following settings, which prevents packages that start withdotnet
,aspnetcore
, ornetstandard
from being sourced from the Microsoft repository:Package: dotnet* aspnet* netstandard* Pin: origin "packages.microsoft.com" Pin-Priority: -10
Reinstall .NET from the distribution's package feed. For more information, see Install .NET on Linux.
No
Remove the existing .NET packages from your distribution. You want to start over and ensure that you don't install them from the wrong repository.
sudo apt remove 'dotnet*' 'aspnet*' 'netstandard*'
Delete the Microsoft repository feed from your distribution.
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list sudo apt update
Reinstall .NET from the distribution's package feed. For more information, see Install .NET on Linux.
I need a version of .NET that isn't provided by my Linux distribution
Configure your package manager to ignore the .NET packages from the distribution's repository. It's possible that you've installed .NET from both repositories, so you want to choose one or the other.
Remove the existing .NET packages from your distribution. You want to start over and ensure that you don't install them from the wrong repository.
sudo dnf remove 'dotnet*' 'aspnet*' 'netstandard*'
Configure the Linux repository to ignore .NET packages.
echo 'excludepkgs=dotnet*,aspnet*,netstandard*' | sudo tee -a /etc/yum.repos.d/<your-package-source>.repo
Make sure to replace
<your-package-source>
with your distribution's package source.Reinstall .NET from the distribution's package feed. For more information, see Install .NET on Linux.
Configure your package manager to ignore the .NET packages from the distribution's repository. It's possible that you've installed .NET from both repositories, so you want to choose one or the other.
Remove the existing .NET packages from your distribution. You want to start over and ensure that you don't install them from the wrong repository.
sudo apt remove 'dotnet*' 'aspnet*' 'netstandard*'
Create
/etc/apt/preferences
, if it doesn't already exist.touch /etc/apt/preferences
Open
/etc/apt/preferences
in an editor and add an apt preferences fragement to prevent packages that start withdotnet
,aspnetcore
, ornetstandard
from being sourced from the distribution's repository.Package: dotnet* aspnet* netstandard* Pin: origin "<your-package-source>" Pin-Priority: -10
Make sure to replace
<your-package-source>
with your distribution's package source.Your distribution may have more than one package source.
For example, on Ubuntu in the US, you may need to use one fragment for
archive.ubuntu.com
and another forsecurity.ubuntu.com
. Separate each fragment with a blank line like this:Package: dotnet* aspnet* netstandard* Pin: origin "archive.ubuntu.com" Pin-Priority: -10 Package: dotnet* aspnet* netstandard* Pin: origin "security.ubuntu.com" Pin-Priority: -10
Tip
Use the
apt-cache policy
command to find the source:apt-cache policy '?name(dotnet.*)' | grep -v microsoft | grep '/ubuntu' | cut -d"/" -f3 | sort -u
Tip
If you registered the Ubuntu .NET backports package repository you should unregister the Ubuntu .NET backports package repository instead of configuring your package manager to ignore the contained .NET packages. Otherwise your package manager pulls the package index from this repository, just to ignore it, because the repository only contains .NET packages. This effectively slows down updating your local package index every time you call
apt update
.Use the
apt-cache policy
command to check if you registered the Ubuntu .NET backports package repository:apt-cache policy '?name(dotnet.*)' | grep 'ppa.launchpadcontent.net/dotnet/backports' | sort -u
Reinstall .NET from the Microsoft package feed. For more information, see Install .NET on Linux. If using Ubuntu, see My Ubuntu distribution doesn't include the .NET version I want, or I need an out-of-support .NET version.
Online references
Many other users have reported these problems. The following is a list of those issues. You can read through them for insights on what may be happening:
System.IO.FileNotFoundException and '/usr/share/dotnet/packs/Microsoft.NETCore.App.Ref/5.0.0/data/FrameworkList.xml'
- SDK #15785: unable to build brand new project after upgrading to 5.0.3
- SDK #15863: "MSB4018 ResolveTargetingPackAssets task failed unexpectedly" after updating to 5.0.103
- SDK #17411: dotnet build always throwing error
- SDK #12075: dotnet 3.1.301 on Fedora 32 unable to find FrameworkList.xml because it doesn't exist
Fatal error: libhostfxr.so couldn't be found
Fatal error: folder /host/fxr doesn't exist
Fatal error: folder /host/fxr doesn't contain any version-numbered child folders
Generic errors without clear messages