How to Resolve /usr/share/dotnet/host/fxr does not exist For Dotnet


So, I had spin up a new Ubuntu 22.04 server on AWS cloud, and choose to install dotnet 6 on it for my backend application that talks to a database. The whole installation went smoothly, however, when I typed in dotnet -v to check if the application really installed, I was greeted with a funny looking set of error.

The error A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist is a pretty interesting error that is unique to the Ubuntu 22.04 machine.

usr/share/dotnet/host/fxr error for dotnet problems resolved
the Cause

The cause is when there is conflict on the choice of installed dotnet package manager inside the server. For Ubuntu and some other linux operating system, they have their own repository which also contain dotnet, while this was an okay development, Microsoft (the creator of dotnet) also developed their own repository for their packages, this includes the dontet too.

Therefore, both of the repositories with the dotnet package in the server conflicts, which resulted into A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist.

the solution

Resolving this error is pretty easy, all you need to do is to specify one repository (any one of the repositories) to be the source of the dotnet package. We select only one because each repository have different directory path where the store their activities.

We will walk through how to select either Microsoft repositories or Ubuntu repositories shortly.

the steps

To resolve, lets follow the next few steps. We will start with the Microsoft repository option. If you prefer to use Ubuntu repository with is much easier to use, you can skip this step to the next.

to use microsoft repository

1. We need to uninstall the dotnet packages from the machine. Do not panic, we will reinstall them as we go in this walk through.

sudo apt remove dotnet*
usr/share/dotnet/host/fxr error for dotnet problems resolved
sudo apt remove aspnetcore*
usr/share/dotnet/host/fxr error for dotnet problems resolved
sudo apt remove netstandard*
usr/share/dotnet/host/fxr error for dotnet problems resolved

2. The next step is to create and add the package origin to the pref file inside the preference.d directory.

sudo nano /etc/apt/preference.d/99microsoft-dotnet.pref
usr/share/dotnet/host/fxr error for dotnet problems resolved dotnet

Paste the code snippet below in the file
package: *
Pin: origin ""
Pin-Priority: 1001

microsoft package repository

Once that is done, we need to update the apt repository on the machine to reflect our changes.

sudo apt update apt update

Cool, now let’s reinstall the dotnet that we uninstall earlier. You can install any of the dotnet that works for your application, however, I installed the 6.0 SDK version, because that is what my application requires.

sudo apt install dotnet-sdk-6.0 blog

After the installation is done, you can confirm that dotnet is installed properly by checking the version.

dotnet --version
version check blog
to use the ubuntu repository

Also, if you choose to use the Ubuntu repository, you can do that is 3 steps.

First, remove the microsoft-prod.list file from the Ubuntu source list in apt directory

sudo rm /etc/apt/sources.list.d/microsoft-prod.list

Then you can go ahead to update the apt repository.

sudo apt update

Then install the dotnet you prefer to install. And, lastly, check the version using the dotnet -v command.

sudo apt install dotnet-sdk-6.0

Now you have no worry when next you find this error. I recommend you bookmark this page for future reference.






Leave a Reply

Your email address will not be published. Required fields are marked *