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:

#!/bin/sh
/home/user/myscripts/botScript.sh

Contents of botScript.sh:

#!/bin/bash
cd /home/user/bot/
nohup dotnet run --configuration Release &

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

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: path1
   at System.IO.Path.Combine(String path1, String path2, String path3)
   at Microsoft.DotNet.ProjectModel.Resolution.PackageDependencyProvider.ResolvePackagesPath(String rootDirectory, GlobalSettings settings)
   at Microsoft.DotNet.Configurer.NuGetCacheSentinel.get_NuGetCachePath()
   at Microsoft.DotNet.Configurer.NuGetCacheSentinel.Exists()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.ShouldPrimeNugetCache()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

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:

#!/bin/bash
cd /home/user/bot/
export NUGET_PACKAGES="/home/user/.nuget/packages" # <=== 
nohup dotnet run --configuration Release &

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

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