Dotnet complains about dynamically linked binaries, but only if multiple SDKs are installed

Hello there! At my current workplace we write applications in .NET (C#), and I am running into some issues when having multiple .NET SDKs installed.

I created a very simple hello-world web-api using .NET 8, which works great when .NET 9 is not installed. However if I install .NET 9 I wont be able to run .NET 8 applications anymore, as it complains about dynamically linked binaries, .NET 9 apps will run fine though. I have attempted to look into nix-ld, but I can’t wrap my head around it, and also why it should be required depending on which SDKs I have installed.

without dotnetCorePackages.sdk_9_0 installed

with dotnetCorePackages.sdk_9_0 installed

I have .NET installed through home-manager with the following configuration

{ pkgs, lib, config, ... }:
{
  options = {
    dotnet.enable = lib.mkEnableOption "enable dotnet";
  };
  config = lib.mkIf config.dotnet.enable {
    home.packages = with pkgs; [
      netcoredbg
      (with dotnetCorePackages; combinePackages [
        sdk_7_0_3xx
        sdk_8_0_2xx
        sdk_9_0 
      ])
    ];
  };
}

So why don’t I just use nix shell, direnv and flakes for each project?
I have not really found a way to work it into my workflow yet with also using Rider, and also I am the only developer on my team using Nix, so the files in our version control for our project would only make sense to me.

I hope someone can enlighten me as to what is happening, such that I can have multiple versions of the SDK installed without weird issues.

Thanks in advance!

1 Like

Just to let others know, I never ended up solving this issue the way I wanted, but I did manage to make a compromise by using external devshells and direnv, which I am quite happy with.

  1. I created a separate repo for devshells, currently I only have my .NET 8 shell in there
  2. Inside each project where this shell is needed i added a .envrc file with the content use flake ~/devshells/dotnet8 --impure such that direnv can load the shell when entering the directory
  3. Add .direnv/ and .envrc to .gitignore. I considered letting .envrc stay in the repo, but the path inside it only makes sense to me anyway.

When starting Rider, it needs to be done from within the shell for it to pick up the binaries it needs to compile and run .NET code, just keep that in mind. Usually I create a new window in TMUX from where I run Rider.

I hope this can help someone else.

1 Like