Skip to content
Advertisement

`Unhandled Exception: System.ArgumentNullException: Value cannot be null.` error while running `dotnet run` using a startup script

I’m trying to run a dotnet app using dotnet run --configuration Release at system server Startup/Reboot. I’m using a init.d script to acheive the same.

My startup script, located at /etc/init.d/myscript contains the following:

JavaScript

Contents of botScript.sh:

JavaScript

When my server Starts or Reboots the startup script gets executed but dotnet run doesn’t work. I get the following error(s):

JavaScript

But all other commands works fine in that script & even simply running dotnet works fine too (I have checked that). It’s just that dotnet run doesn’t work.

Yeah, but when I run the scripts, both myscript as well as botScript.sh, after loging in to my server, it works fine without any errors.

Please, can anyone help me out on this?

Advertisement

Answer

There’s obviously a bug in PackageDependencyResolver, but to find a workaround, consider the order in which the packages folder is found:

  1. global.json { "packages": "..." }
  2. NUGET_PACKAGES environment variable.
  3. {DefaultLocalRuntimeHomeDir}packages

Your code is falling all the way to case #3 above. To work around this, create an environment variable called NUGET_PACKAGES pointing to you packages folder. For example, in botScript.sh:

JavaScript

For more info, see PackageDependencyResolver.cs and PackageDependencyResolver.cs

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement