Vstest: Visual Studio doesn't find tests for net462 x64

Created on 30 Jun 2017  路  2Comments  路  Source: microsoft/vstest

Description

Visual Studio doesn't seem to be able to find any tests as soon as this line is added to the csproj,
<PlatformTarget>x64</PlatformTarget>

Steps to reproduce

Create a new xUnit test project in Visual Studio, and change TargetFramework to net462 and PlatformTarget to x64

Expected behavior

VS finds the initial test in the template.

Actual behavior

Visual Studio doesn't find any tests, output is below,

[6/30/2017 4:06:12 PM Informational] ------ Discover test started ------
[6/30/2017 4:06:12 PM Warning] Test run will use DLL(s) built for framework Framework45 and platform X86. Following DLL(s) will not be part of run: 
XUnitTestProject1.dll is built for Framework Framework45 and Platform X64.
 Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
[6/30/2017 4:06:12 PM Warning] [xUnit.net 00:00:00.1490549] Exception discovering tests from XUnitTestProject1: System.BadImageFormatException: Could not load file or assembly 'XUnitTestProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'XUnitTestProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at Xunit.Sdk.ReflectionAssemblyInfo..ctor(String assemblyFileName)$$RethrowMarker$$   at ExceptionExtensions.RethrowWithNoStackTraceLoss(Exception ex)
   at Xunit.AppDomainManager_AppDomain.CreateObject[TObject](AssemblyName assemblyName, String typeName, Object[] args)
   at Xunit.Xunit2Discoverer..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, IAssemblyInfo assemblyInfo, String assemblyFileName, String xunitExecutionAssemblyPath, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk)
   at Xunit.XunitFrontController.CreateInnerController()
   at Xunit.XunitFrontController.get_InnerController()
   at Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner.DiscoverTests[TVisitor](IEnumerable`1 sources, LoggerHelper logger, Func`4 visitorFactory, Action`4 visitComplete)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) 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].

[6/30/2017 4:06:12 PM Informational] ========== Discover test finished: 0 found (0:00:00.161) ==========

dotnet test does work however,

Build started, please wait...
Build completed.

Test run for C:\Users\user\source\repos\XUnitTestProject1\XUnitTestProject1\bin\Debug\net462\XUnitTestProject1.dll(.NETFramework,Version=v4.6.2)
Microsoft (R) Test Execution Command Line Tool Version 15.3.0-dev
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
[xUnit.net 00:00:00.4120680]   Discovering: XUnitTestProject1
[xUnit.net 00:00:00.5337503]   Discovered:  XUnitTestProject1
[xUnit.net 00:00:00.9200783]   Starting:    XUnitTestProject1
[xUnit.net 00:00:01.0981913]   Finished:    XUnitTestProject1

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1.3370 Seconds

Environment

Win7 x64
VS 2017 15.3 Preview 3
.NET Core 2 Preview 2

Most helpful comment

@xqrzd
Can you please try setting the default architecture to x64?

x64_net46_issue

All 2 comments

@xqrzd
Can you please try setting the default architecture to x64?

x64_net46_issue

That fixed it, thanks!

Was this page helpful?
0 / 5 - 0 ratings