Troubleshoot .NET errors related to missing files on Linux
Article
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.
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
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.
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.
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 with dotnet, aspnetcore, or netstandard from being sourced from the Microsoft repository:
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.
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.
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 fragment to prevent packages that start with dotnet, aspnetcore, or netstandard from being sourced from the distribution's repository.
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 for security.ubuntu.com. Separate each fragment with a blank line like this:
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:
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'
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Create a .NET project and learn to add packages and manage package dependencies in your project. Use the .NET Core CLI and NuGet registry to add libraries and tools to your C# applications through Visual Studio Code.