Exception discovering xUnit.net tests with Visual Studio Online build server - unit-testing

I am using Xunit.net with Visual Studio Online hosted build. My tests are being discovered and run fine both locally and on the build server. But on the build server I get this exception (causing the build to reach a "Partially Succeeded" state). This is odd, since all my tests are in fact being discovered and run.
[xUnit.net 00:00:01.3170293] Exception discovering tests from C:\a\bin\xunit.runner.visualstudio.testadapter.dll: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value HKLM\Software\Microsoft\Fusion!EnableLog to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at Xunit.Sdk.Executor.EnumerateTests..ctor(Executor executor, Object _handler)$$RethrowMarker$$ at ExceptionExtensions.RethrowWithNoStackTraceLoss(Exception ex)
at Xunit.RemoteAppDomainManager.CreateObjectTObject
at Xunit.Xunit1Executor.EnumerateTests(ICallbackEventHandler handler)
at Xunit.Xunit1.Find(Predicate`1 filter, Boolean includeSourceInformation, IMessageSink messageSink)
at Xunit.Xunit1.Find(Boolean includeSourceInformation, IMessageSink messageSink)
at Xunit.XunitFrontController.Find(Boolean includeSourceInformation, IMessageSink messageSink)
at Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner.GetTests(IEnumerable`1 sources, IMessageLogger logger, XunitVisualStudioSettings settings, Stopwatch stopwatch)
See http://go.microsoft.com/fwlink/?LinkId=254169
I have the following nuget packages installed in the test project:
xunit 1.9.2
xunit.runner.visualstudio 0.99.2
Other unit testing frameworks, such as MS Test and NUnit, are working without problems. This makes me think the issue is with Xunit.net rather than with Visual Studio Online.
I have also opened an issue at the xUnit.net GitHub, but it remains unsolved.
https://github.com/xunit/xunit/issues/47
How can I get this working? Does anyone know of a workaround? Could I somehow suppress the error message?

The testrunner tries to discover the unit tests in xunit.runner.visualstudio.testadapter.dll. Why? Because it matches the default test sources spec of *.test*.dll.
When changing the default test source spec to *.tests.dll or something else more specific, it will work.
Source: http://erictummers.wordpress.com/2014/02/11/execute-xunit-tests-on-hosted-build-controller/

Related

webjob failing / file not found exception / Microsoft.WindowsAzure.Storage

I'm pretty sure I understand the error, I just don't understand why and why now.
Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'Microsoft.WindowsAzure.Storage, Version=9.3.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
Sure enough the version the web site is:
My question is that this was a running web job which ran successfully back in 2018-09-03 - why is it failing on the versioning of an assembly now?
After this time, we simply turned down the resources of the web site, and waiting for the next time the system would be used.
This year, I cranked up the resources and it's now failing! The Web.config has no reference to this file or the version - so I'm thinking it should just find the dll, but I don't know why it's referring to the 9.3.0.0 version, and why the reference to the 7.2.1.0 version?
I really don't want to take the time to re-deploy and recompile, as that will then require a full regression test - and the client will simply not pay for something that should just be running.
What am I missing?

Error while running unit tests in debug mode in VS2017

While running my unit test in VS2017 in debug mode, after the build the run starts but immediately after i get an exception before any of my breakpoints are hit:
Managed Debugging Assistant 'BindingFailure'
Message=Managed Debugging Assistant 'BindingFailure' :'*The assembly with display name 'Microsoft.VisualStudio.TestPlatform.Extensions.MSAppContainerAdapter' failed to load in the 'Load' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.Extensions.MSAppContainerAdapter' or one of its dependencies. The system cannot find the file specified.*'
How can I figure it out where is this issue coming from?
The file in the exception message can be found under:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions and has the version 15.0.28307
The VS2017 that i use has the version 15.9.11

Nugetserver onpremise unable to run due to newtonsoft.json version

Target set as .net 4.6 in a vs2015 environment. All fetch and built no errors.
Used https://www.hanselman.com/blog/HowToHostYourOwnNuGetServerAndPackageFeed.aspx and MS doco as reference.
When run under IIS, shows error below
How do I resolve this ?
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
NB: Version on the Newtonsoft.Json.dll file is 9.0.1.19813
web.config has these 2 lines, do I need to make this and nugget.dll.config have newVersion="9.0.2.0" say ?
< assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
< bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.1.0" />
I have it working, what I did was change the default project of "nuget" to "nugetwebserver" and adjusted the assemblies and module name.
Then did a fresh compile. I suspect the poor choice of name caused some conflict with the some setting seeing by nuget.server project was called ..
Interestingly the http://server/nugetserver2.7/nuget would render in IE
http://server/nugetserver3.1/nuget asks me if I want to download the content. The content being the same as the rendered page for 2.7..

TeamCity NUnit build step failing although all tests pass

I'm setting up TeamCity to run some NUnit tests, TeamCity reports that all the test pass but it reports the build as a fail with the error message 'New build status is : : NUnit error, {build.status.text}'.
Digging in to the build log I can see that there's a failure to load the program under test, here's the reported error;
[Step 2/2] NUnit error running tests in 'C:\TeamCity\buildAgent\work\f73bb9cce36ccd59\ProjectName.Web\ProjectName.BrowserTests\obj\Release\MyProject.BrowserTests.dll' assembly
Loading assembly is compiled for v4.0.30319, MSIL
NUnit runner runtime is v4.0.30319, x86
System.IO.FileNotFoundException: Could not load file or assembly 'MyProject.Browser, Version=0.24.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'MyProject.Browser, Version=0.24.0.0, Culture=neutral, PublicKeyToken=null'
Server stack trace:
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at NUnit.Core.CoreExtensions.InstallAdhocExtensions(Assembly assembly)
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites)
at NUnit.Core.TestSuiteBuilder.Build(TestPackage package)
at NUnit.Core.SimpleTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Core.RemoteTestRunner.Load(TestPackage package)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
So, why can the file not be loaded I wonder? The tests have all passed so why does this file even need to be loaded now?
I've experimented with setting the .NET runtime to x86 in the NUnit build step, to no avail.
Environment: Windows 7, VS 2012 Update 2, compiling to .NET 4.0, NUnit 2.6.2, TeamCity 7.1.
If this is still active;
It is a pretty clear error:
System.IO.FileNotFoundException: Could not load file or assembly 'MyProject.Browser, Version=0.24.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
You have to create build step to compile tests
Create another build step NUnit and pass path to assembly file you can use wildcards, more info https://stackoverflow.com/a/16629676/1075077 here.

Gallio: An exception was thrown while exploring tests: System.Reflection.ReflectionTypeLoadException

I'm able to run my unit tests through VS2010 with the CodeRush but when I try to run the tests with Icarus Test Runner I get this error.
An exception was thrown while exploring tests.
Location: C:\XXX\XXX.Server.Tests\bin\Release\XXX.Server.Tests.DLL
Reference: XXXServer.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at Gallio.Common.Reflection.Impl.NativeAssemblyWrapper.GetTypes()
at Gallio.Framework.Pattern.TestAssemblyPatternAttribute.PopulateChildrenImmediately(IPatternScope assemblyScope, IAssemblyInfo assembly)
at Gallio.Framework.Pattern.TestAssemblyPatternAttribute.Consume(IPatternScope containingScope, ICodeElementInfo codeElement, Boolean skipChildren)
at Gallio.Framework.Pattern.DefaultPatternEvaluator.Consume(IPatternScope containingScope, ICodeElementInfo codeElement, Boolean skipChildren, IPattern defaultPrimaryPattern)
I've made sure Copy Local is set to True for project references.
Tests were being run on a 64bit machine with the test project Platform target set to "Any CPU" while the project being tested was set to "x86". So the machine was loading the tests as 64 which caused the error when trying to load the project being tested the same way.