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

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"

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.

Related

FluentAssertions throws ArgumentOutOfRangeException when assertion fails (possibly NCrunch related)

I'm using FluentAssertions 5.3.0 run under NCrunch 3.14.0.1. When a test fails, I often seen this error as FluentAssertions tries to generate a report message...
System.ArgumentOutOfRangeException: startIndex cannot be larger than
length of string. Parameter name: startIndex at
System.String.Substring(Int32 startIndex, Int32 length) at
FluentAssertions.CallerIdentifier.ExtractVariableNameFrom(StackFrame
frame) at
FluentAssertions.CallerIdentifier.DetermineCallerIdentity() at
FluentAssertions.Execution.AssertionScope.GetIdentifier() at
FluentAssertions.Execution.AssertionScope.FailWith(String message,
Object[] args) at FluentAssertions.Numeric.NumericAssertions`1.Be(T
expected, String because, Object[] becauseArgs) at
TableTests.ConsolidatedMovementsTester.AlternativingMovementStatesAreRecognised()
in ...test.cs
The error is sporadic - often it will disappear if the test is rerun (in which case, a proper error report is shown). I've seen this in the last couple of versions of both FluentAssertions and NCrunch and it appears on multiple machines (all running some flavour of Visual Studio 2017 Professional).
Here's an example of the latest call to bite me...
results.Count(c => c.IsStationary).Should().Be(5);
where results is an ImmutableArray of POCOs
In this case, right-clicking on the failing test and selecting "rerun in new test runner" in the ncrunch window, caused the test to re-run and FA to emit the correct report.
Can anyone suggest a workaround for this?

SonarQube 5.1 execution error using Bamboo

I have MSBuild.SonarQube.Runner.exe running on my own computer and everything is working fine. I am now trying to automate this job and give it to Bamboo. I am using the same SonarQube configuration (but not the same environment as it is a Windows 2008 R2 Server versus Windows 7). I am using MSBuild.SonarQube.Runner.exe with the simplest configuration file (only the MySQL server).
My error indicates a path to Dinesh's desktop (if I'm not mistaking, he's a Sonar Qube developer)
This error happens after running MSBuild.SonarQube.Runner.exe end. Any idea ?
18:00:06 Writing processing summary to E:\bamboo-home\xml-data\build-dir\SON-SVACN0-TEST\.sonarqube\out\ProjectInfo.log
18:00:06 Creating directory: E:\bamboo-home\xml-data\build-dir\SON-SVACN0-TEST\.sonarqube\bin\sonar-runner
18:00:06 The SONAR_RUNNER_HOME environment variable is not required and will be ignored.
18:00:06 Calling the sonar-runner...
18:00:06 SONAR_RUNNER_OPTS is not configured. Setting it to the default value of -Xmx1024m
Unhandled Exception: System.ArgumentException: Item has already been added. Key in dictionary: 'bamboo_capability_system_builder_snr_Sonar_Runner' Key being added: 'bamboo_capability_system_builder_snr_Sonar_runner'
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at System.Collections.Specialized.StringDictionaryWithComparer.Add(String key, String value)
at System.Diagnostics.ProcessStartInfo.get_EnvironmentVariables()
at SonarQube.Common.ProcessRunner.SetEnvironmentVariables(ProcessStartInfo psi, IDictionary`2 envVariables, ILogger logger) in c:\Users\dinesh\Desktop\sonarsource\sonar-msbuild-runner\SonarQube.Common\ProcessRunner.cs:line 151
at SonarQube.Common.ProcessRunner.Execute(String exeName, String args, String workingDirectory, Int32 timeoutInMilliseconds, IDictionary`2 envVariables, ILogger logger) in c:\Users\dinesh\Desktop\sonarsource\sonar-msbuild-runner\SonarQube.Common\ProcessRunner.cs:line 87
at SonarRunner.Shim.SonarRunnerWrapper.ExecuteJavaRunner(ILogger logger, String exeFileName, String propertiesFileName) in c:\Users\dinesh\Desktop\sonarsource\sonar-msbuild-runner\SonarRunner.Shim\SonarRunner.Wrapper.cs:line 114
at SonarRunner.Shim.SonarRunnerWrapper.Execute(AnalysisConfig config, ILogger logger) in c:\Users\dinesh\Desktop\sonarsource\sonar-msbuild-runner\SonarRunner.Shim\SonarRunner.Wrapper.cs:line 68
at SonarQube.TeamBuild.PostProcessor.Program.Main() in c:\Users\dinesh\Desktop\sonarsource\sonar-msbuild-runner\SonarQube.TeamBuild.PostProcessor\Program.cs:line 51
On Windows, environment variables are case-insensitive.
For some reason, you are trying to define both:
bamboo_capability_system_builder_snr_Sonar_Runner
bamboo_capability_system_builder_snr_Sonar_runner
This is not well supported by the .NET framework, see:
https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs#L97
Any call to ProcessStartInfo.Environment when the same environment variable exists with multiple casing will result in the failure you see.
So - perhaps this is something to be fixed in CoreFX (the .NET Framework) - but I do not think a change in the MSBuild SonarQube Runner itself is required.
Another fix is to have Bamboo not to define the same environment variable multiple times. For example, the Windows User Interface to set environment variables overwrites the value if you attempt to define FOO when foo is already defined.
Bamboo is creating many environment variables. The problem is that it creates two times the same variable (Runner vs runner).
bamboo_capability_system_builder_snr_Sonar_Runner=E:\sonar-runner-2.3
bamboo_capability_system_builder_snr_Sonar_runner=E:\sonar-runner-2.3
bamboo_capability_system_builder_snr_Sonar_runners=E:\sonar-runner-2.3
I think there is a bug in MSBuild.SonarQube.Runner as it should check that the key is already contained in this function
at SonarQube.Common.ProcessRunner.SetEnvironmentVariables(ProcessStartInfo psi, IDictionary`2 envVariables, ILogger logger) in c:\Users\dinesh\Desktop\sonarsource\sonar-msbuild-runner\SonarQube.Common\ProcessRunner.cs:line 151
As a quick workaround I decided to set one of the two variables to null in my bamboo script:
set bamboo_capability_system_builder_snr_Sonar_runner=

Team Foundation Server 2013 Error TF400129: Verifying SQL connection

I'm trying to install TFS2013 (en_visual_studio_team_foundation_server_2013_with_update_4_x86_x64) on my machine (windows 8.1 x64)
I had a existing SQL instance installed and tried to use that one during my TFS installation but I kept on getting error messages about TFS not being able to connect to my SQL instance.
I started googling te error message and found guides about how you needed to config the SQL to be put on port 1433, add Firewall Rules,.. I tried literally everything, nothing worked.
So I decided to completely remove my SQL instance and install the SQL SERVER 2012 Express edition that comes with the TFS installer. The SQL installation completes successfully, but when configuring TFS again, the same error popped up.
So I went another step further and removed the SQL Server instance again and downloaded the SQL SERVER 2014 Express edition. Yet, same problem.
I've been looking around the web for the error but can't seem to find anything useful. Note that using a database on the SQL SERVER instance from code or connecting using the SQL Management Studio works like charm!
I started inspecting the full blown error log TFS provided me with and found this:
TF400129: TF400129: Error from readiness check: Verifying SQL
connection [Info #18:58:47.025] +-+-+-+-+-| Verifying SQL connection
|+-+-+-+-+- [Info #18:58:47.025] Starting Node: VSQLCONNECT [Info
#18:58:47.025] NodePath :
VINPUTS/Progress/Conditional/VSQLNOTLOCALDB/VSQLISRUNNING/VSQLCONNECT
> [Error #18:58:47.025] System.OverflowException: Arithmetic operation
resulted in an overflow. at
SNIOpenSyncExWrapper(SNI_CLIENT_CONSUMER_INFO* , SNI_ConnWrapper** )
at SNINativeMethodWrapper.SNIOpenSyncEx(ConsumerInfo consumerInfo,
String constring, IntPtr& pConn, Byte[] spnBuffer, Byte[]
instanceName, Boolean fOverrideCache, Boolean fSync, Int32 timeout,
Boolean fParallel) at
System.Data.SqlClient.SNIHandle..ctor(ConsumerInfo myInfo, String
serverName, Byte[] spnBuffer, Boolean ignoreSniOpenTimeout, Int32
timeout, Byte[]& instanceName, Boolean flushCache, Boolean fSync,
Boolean fParallel) at
System.Data.SqlClient.TdsParserStateObject.CreatePhysicalSNIHandle(String
serverName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]&
instanceName, Byte[] spnBuffer, Boolean flushCache, Boolean async,
Boolean fParallel) at
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,
SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout,
Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean
integratedSecurity, Boolean withFailover)
...
For completeness, this is the error screen I can't pass:
I'm really at a dead end here. Ive been trying to get this fixed for days now and I come here as my last resort. Thanks in advance.

MQQueueManager Constructor throwing FileNotFoundException

I have the following vb.net code:
Imports IBM.WMQ
[...]
MQEnvironment.Hostname = hostName
MQEnvironment.Port = portNumber
MQEnvironment.Channel = channelName
queueManager = New MQQueueManager(queueManagerName) ' error here
which is throwing the following error:
System.IO.FileNotFoundException occurred
FileName=C:\Users\User\Documents\Visual Studio 2012\Projects\[...]\bin\Debug\mqclient.ini
HResult=-2147024894
Message=Could not find file 'C:\Users\User\Documents\Visual Studio 2012\Projects\[...]\bin\Debug\mqclient.ini'.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
I am not using any ini files in the construction of my queue manager, so does anyone have any idea what's going on - why is it even looking for one, and why in the same directory as the program? I have installed the MQ client, and afaik I have all the environmental variables, etc. set up properly.
Thanks for any help you can give
Is that an unhandled or a first chance exception? Internally, the MQ .net layer will try to read a MQClient.ini but should function quite happily without it. It reads the file for compatibility with the C client, and can handle some of the MQClient.ini stanzas. I would not have expected an absence of such a file to cause problems, but it will try to open it internally. Was that the full callstack, as I'd have expected some MQ libraries on the stack otherwise.

Windows Service Fails on Launch

I'm trying to write a windows service. It installs fine, but fails when I run it with the following exception. I've searched for the string "MyNewProgramService", but I can't find any conversions that would throw this error. I've also added try/catch blocks to a bunch of code with custom exception handling without finding where this exception is occuring. I'm thinking it's somewhere in the auto-generated configuartion/setup code. Any ideas?
Event Type: Error
Event Source: MyNewProgram Event
Category: None Event
ID: 0
Date: 4/15/2010
Time: 12:48:34 PM
User: N/A
Computer: 20F7KF1
Description: Service cannot be started. System.InvalidCastException:
Conversion from string "MyNewProgramService" to type 'Integer' is not valid. --->
System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value,
NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
--- End of inner exception stack trace ---
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
at TaskManagerFailureHandlerService.MyNewProgramService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
it falls in method MyNewProgramService.OnStart, there Conversions.ToInteger is called somewhere. Just search for it in method. Then check parameter. It might come from config or something, thats why you don't see string in text.
Check your configuration file.
You might also check the account the service is running as. Just as a test go to the login tab in the services list and have it login under your own account. If the problem vanishes it's a permissions problem.