Search code examples
.netubuntuhost

A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist


I can't access dotnet after an update. Reinstalling dotnet and vscode didn't help.

On Ubuntu 22.04, running dotnet --info produces the output:

A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist


Solution

  • NOTE: Since my answer below for Ubuntu 22.04, Microsoft has published a dedicated page to explain how to resolve this issue, depending on your OS version, location, and whether you want to use Ubuntu or Microsoft packages.

    I recommend following the directions on that page for the most up-to-date info.

    UPDATE NOV 2024: Starting with .NET 9, Microsoft will no longer publish .NET packages for platforms that publish their own packages, including Ubuntu. This is a good thing, because we can continue using Microsoft's repo for other tools without conflicts.

    I'm leaving the original answer below, but I now recommend using Ubuntu's packages instead, since that is the direction Microsoft is headed.

    When .NET (Core) was first released for Linux, it was not yet available in the official Ubuntu repo. So instead, many of us added the Microsoft APT repo in order to install it.

    Now, the packages are part of the Ubuntu repo, and they are conflicting with the Microsoft packages. This error is a result of mixed packages.

    So you need to pick which one you're going to use, and ensure they don't mix. Personally, I decided to stick with the Microsoft packages because I figured they'll be better kept up-to-date.

    First, remove all existing packages to get to a clean state:

    sudo apt remove dotnet* aspnetcore* netstandard*
    

    Then, create a file in /etc/apt/preferences.d (I named mine 99microsoft-dotnet.pref, following the convention that files in such *.d directories are typically prefixed with a 2-digit number so that they sort and load in a predictable order) with the following contents:

    Package: dotnet* aspnet* netstandard*
    Pin: origin "archive.ubuntu.com"
    Pin-Priority: -10
    
    Package: dotnet* aspnet* netstandard*
    Pin: origin "security.ubuntu.com"
    Pin-Priority: -10
    

    This will "demote" the Ubuntu packages so that the Microsoft packages take precedence.

    Then, the regular update & install:

    sudo apt update && sudo apt install -y dotnet-sdk-8.0
    

    Note, the above example shows .NET 8; replace with another version if you prefer. .NET SDKs are installed side-by-side, so you can also install multiple versions.

    If you would rather use the official Ubuntu packages, remove all the existing packages as above, but instead of creating the /etc/apt/preferences.d entry, just delete the Microsoft repo:

    sudo rm /etc/apt/sources.list.d/microsoft-prod.list
    sudo apt update
    sudo apt install dotnet-sdk-7.0
    

    However, note that the Microsoft repo contains other packages such as PowerShell, SQL Server Command-Line Tools, etc., so removing it may not be desirable.

    I'm sure it's possible to make the APT config more specific to just these packages, but this is working for me for now. Hopefully Microsoft and Ubuntu work together to fix this soon.

    More info on the issue and various solutions is available here: