Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting UnauthorizedAccessException when deploying asp.net core app using Kudu build service

I have set up Continuous Deployment of my aspnet core 2.2 app using Kudu build service (directly connected through GitHub). It was fine until the day before yesterday but started getting UnauthorizedAccessException when I try to deploy anything since yesterday. Nothing changed in my application though. Any idea what could be wrong here??

Here is the detail exception:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at Internal.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
   at Internal.Win32.RegistryKey.SetValue(String name, String value)
   at System.Environment.SetEnvironmentVariableFromRegistry(String variable, String value, Boolean fromMachine)
Failed exitCode=1, command=dotnet restore "D:\home\site\repository\myproject.sln"
   at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
An error has occurred during web site deployment.
   at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
   at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.\r\n   at Internal.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)\r\n   at Internal.Win32.RegistryKey.SetValue(String name, String value)\r\n   at System.Environment.SetEnvironmentVariableFromRegistry(String variable, String value, Boolean fromMachine)\r\n   at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)\r\n   at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)\r\n   at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()\r\n   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()\r\n   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)\r\n   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)\r\n   at Microsoft.DotNet.Cli.Program.Main(String[] args)\r\nD:\Program Files (x86)\SiteExtensions\Kudu\86.20224.4450\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
like image 458
Janak Avatar asked Jan 25 '23 04:01

Janak


1 Answers

After trying "dotnet restore --help" inside kudu and getting the same error I realized that the error was connected to doing "dotnet restore" inside kudu and not with my application. After looking at the code related to the error message https://github.com/dotnet/sdk/blob/5d747e7b4f1450a00eff5844bd76b73588531b2c/src/Cli/dotnet/Program.cs#L152 I realized that I could solve the issue by adding a new application setting with the name DOTNET_ADD_GLOBAL_TOOLS_TO_PATH and the value false

Application setting

After that I could deploy my application using kudu as I did before.

like image 159
Nils Hedström Avatar answered Mar 02 '23 00:03

Nils Hedström