Thursday, September 07, 2023

dot net app (on Linux) broke - "Forbidden" error - needs roll-forward

The issue turned out to be -

  1. some dot net commands like
    dotnet --version
    would not work due to mismatch between Ubuntu and Microsoft tracks for dotnet. Fixed with help from this blog post,

    # first remove everything
    sudo apt remove dotnet*
     sudo apt remove aspnetcore*
     sudo apt remove netstandard*
    sudo rm /etc/apt/sources.list.d/microsoft-prod.list
     sudo apt update
    sudo apt upgrade


    Then as in the original install link
    https://www.syncfusion.com/blogs/post/hosting-multiple-asp-net-core-apps-in-ubuntu-linux-server-using-apache.aspx

    wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    sudo apt-get update; sudo apt-get install -y apt-transport-https && sudo apt-get update && sudo apt-get install -y aspnetcore-runtime-7.0

    dotnet --list-runtimes
    # pinned as per the troubleshooting blog post
    sudo nano /etc/apt/preferences
    Package: dotnet-* aspnetcore-* netstandard-*
    Pin: origin "packages.microsoft.com"
    Pin-Priority: 999

    #set /etc/dotnet/install_location to /usr/share/dotnet.

    #Then fix the missing DOTNET_ROOT environment variable and add (re-add?) that path #to the PATH environment variable in ~/.bashrc
    sudo apt update
    sudo apt install dotnet-sdk-7.0


  2. Next, the particular dot net app was targeting 7.0.0 - and that framework was not being found, since it had been updated to 7.0.400 or 7.0.10 (depending on whether it was the runtime or the sdk. Running from the commandline gave this error,

    dotnet ourdll.dll

    Framework: 'Microsoft.NETCore.App', version '7.0.0' (x64)
    .NET location: /usr/share/dotnet/

    No frameworks were found.

    and
    /usr/bin/dotnet --info

    Host:
      Version:      7.0.10
      Architecture: x64
      Commit:       a6dbb800a4
     
    Informed the developers,

    it is targeting dot net 7.0.0 and yesterday an update was rolled out to dot net, and the dot net is currently at 7.0.10

    You would need to target using roll-forward - so that updates to dot net do not break the app -
    Select which .NET version to use - .NET | Roll forward
     
    Instead of targeting 7.0.0 alone, you need to retarget the app using 7.0.* as mentioned in the above link.
    They seem to have fixed it by adding the "rollForward": "LatestMinor" in the runtimeconfig.json file.

  3. As suggested by the developers, disabled automatic updates, so that this issue won't happen for the next major upgrade of dotnet. Set up apticron to inform me of pending updates. Set up the "mail" command using ssmtp as in this earlier post

    apt - How to make my server email me when there are security updates? - Ask Ubuntu 

    sudo nano /etc/apt/apt.conf.d/20auto-upgrades
    # set both to 0
    sudo apt install apticron
    cd /etc/apticron
    more README
    sudo cp '/usr/lib/apticron/apticron.conf' . -v
    sudo nano apticron.conf
    # set it with
    NOTIFY_NO_UPDATES="1"
    # so that I'll know if it's working, by emailing every day
    .

No comments:

Post a Comment