Tests that use Fakes/Shims fail on server, but succeed in local - testing

Tests that use Fakes/Shims fail on build server, but succeed in local.
This following error is gone when I remove the test that uses shims. Do I need to do any specific configuration on build server?
On a side note, I'm using shims in my specflow test cases.
Run has the following issue(s):
One of the background threads threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , IContextManager )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType bindingEvent)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnTestRunEnd()
at TechTalk.SpecFlow.TestRunner.OnTestRunEnd()
at TechTalk.SpecFlow.TestRunnerManager.OnTestRunnerEnd()
at TechTalk.SpecFlow.TestRunnerManager.
Further debugging gives the following error,
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitT‌​estIsolationExceptio‌​n: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables.

Related

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"
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.

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=

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.

Access Denied Error for a method in web service

I have a webservice that works perfectly from localhost but when I hosted it on the testing server I get an error on one of the methods. I am using wsHttp Binding. everything else works fine on the client side except for this method. This is the error that I am getting
client error:
System.ServiceModel.Security.SecurityAccessDeniedException: Access is denied.
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Server error:
namespace.Service Error: 10001 : Error occurred in methodname().
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String machineName)
at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)
at System.Diagnostics.EventLog.WriteEvent(EventInstance instance, Byte[] data, Object[] values)
at System.Diagnostics.EventLog.WriteEvent(EventInstance instance, Object[] values)
at System.Diagnostics.EventLogTraceListener.TraceEvent(TraceEventCache eventCache, String source, TraceEventType severity, Int32 id, String format, Object[] args)
at System.Diagnostics.TraceSource.TraceEvent(TraceEventType eventType, Int32 id, String format, Object[] args)
at AutoWatch.Entity.WcfService.TrackingService.UpdateIncidentStatusHistory(Int64 incidentId, String status, String username, String comment, Boolean SuspectFaultyUnit) in C:\..servicename.cs:line 566
at AutoWatch.Entity.WcfService.TrackingService.GetNewIncidentMessage(String username) in C:\..servicename.cs:line 444
The Zone of the assembly that failed was:
MyComputer
I added in the error I am getting on the server.
Is it possible I am getting this error because the service cannot write to the event log?
Please help.
Ensure that account running your process where the service is hosted has access rights to the database. For example in case of IIS the account running the application pool where the service is hosted must have login to database server and it must have permissions to do all necessary operations in your database.
Edit:
The server stack trace looks quite straightforward. You have a problem with writing to Windows Event Log! It cannot find source you requested and it doesn't have permission to create it.
I got the same error when I tried to use the following statement in a Web Method of a WCF Service:
string myTypeName = typeof(ErrorHandlerBehavior).AssemblyQualifiedName;
where ErrorHandlerBehavior derives from BehaviorExtensionElement.
The line works well when I test the service on my localhost. On the web, the call of the containing method raises the Exception "Access is denied".
In this case, I guess that the cause was that my IP does not allow the creation of a BehaviourExtensionElement in a Partially Trusted environment (my service is in a shared hosting environment).
Finally, I succeded following the first mechanism described at https://learn.microsoft.com/en-us/dotnet/framework/wcf/extending/configuring-and-extending-the-runtime-with-behaviors about Service Behaviors:
"Using an attribute on the service class. When a ServiceHost is constructed, the ServiceHost implementation uses reflection to discover the set of attributes on the type of the service. If any of those attributes are implementations of IServiceBehavior, they are added to the behaviors collection on ServiceDescription. This allows those behaviors to participate in the construction of the service run time."
I just modified the derivation (no other modification required):
public class ErrorServiceBehavior : Attribute, IServiceBehavior
{ ... }
and use the class as Attribute of my service:
[ErrorServiceBehavior()]
public partial class MyService : IMyService
{...}
No other modification required. Check the original sample at How do I create a global exception handler for a WCF Services?.