MSTest refuses to run 64-bit?

18

I am writing tests for an application using Outlook Redemption that absolutely must run 64-bit (it connects to windows MAPI and Outlook x64). Unfortunately, I cannot for the life of me make it run the test in 64-bit. I have tried using a .runsettings file (edited to indicate 64-bit) and a .testsettings file (also edited), and finally I have selected Test>TestSettings>Default Processor Architecture>64-bit, to no avail.

Every time, System.Environment.Is64BitProcess is false, and when I load the dll to connect to Outlook and MAPI I get the dreaded COM Exception: Wrong OS or OS version for application (Exception from HRESULT: 0x800401FA (CO_E_WRONGOSFORAPP)) which indicates that 64-bit Outlook is installed and the process trying to access it is 32-bit.

I have restarted VS 2012 after making settings changes as I have read somewhere that a restart may be necessary. Does anyone have any other suggestions? I could just write this as a console app that runs informal tests and reports their status, but my next step is to get these tests integrated into the automated build. Any help would be greatly appreciated.

Edit

Screenshot of Host Settings page in .testsettings enter image description here

Experiment

Interestingly, I did a little experiment. I created a new solution with a single console app project. I put a public method in there that just returned true. When I ran the console app, and paused execution, I looked and indeed it is running 64-bit; no problem there. I then added a test project, created a single test which called the method. I also added var is64 = Environment.Is64bitProcess and put a breakpoint after it.

Predictably, without changing any options, is64 was false. I chose the 64-bit default architecture from the dropdown under test, then cleaned the solution, and ran the test again, same result, running 32-bit. I restarted VS2012, cleaned, built, same result. I created a testsettings file and referenced it in the Test menu, clean build, same, restart,clean, build same. I created a runsettings file, set <TargetPlatform>x64</TargetPlatform> , referenced that in the test menu, ran through it all again, and came up with the same results. QTAgent32.exe continues to run the process, and absolutely refuses to heed my demands that it run 64 bit.

I swear, if I have to delete QTAgent32.exe and rename QTAgent to that name, I will. I am not above cramming my wishes down the computers throat when it wants to be obstinate. Please, if you dont want to see me mistreat a workstation, someone show me what is going wrong. Think of the computers.

c#
.net
64-bit
mstest
outlook-redemption
asked on Stack Overflow Jul 17, 2013 by CodeWarrior • edited Jul 19, 2013 by CodeWarrior

3 Answers

22

If you use VS2012, then you will be able to select your platform x64 through test settings as below;

enter image description here

In this example I am referring to .runsettings file. the settings are

enter image description here

But if wish to run your test through command line you need to use vstest.console.exe instead of MSTEST as it doesn't support for x64 test.dlls

you will find vstest.console.exe at "C:\Program Files (x86)\Common7\IDE\CommonExtensions\Microsoft\TestWindow\"

Please note below steps

  1. Open CMD
  2. Navigate to "C:\Program Files (x86)\Common7\IDE\CommonExtensions\Microsoft\TestWindow\"
  3. execute vstest.console.exe "C:\Projects\Test\Test.Automation.Specs.dll" /InIsolation /platform:x64

Note : Test.Automation.Specs.dll is your test project and you need to define full path

I hope this help

answered on Stack Overflow Apr 16, 2015 by Shiran Jayawardena
8

I ran into the same issue just now. Here are the steps you can follow to fix the problem.

  1. Switch default processor architecture for unit tests from x86 to x64: Go to Test->Test Settings->Default Processor Architecture->x64. Screenshot for changing the default processor architecture to x64 for test settings.
  2. Change the Build settings for the unit test project to x64.Screenshot for changing the build settings to x64.
  3. Clean the solution then rebuild the solution. Your unit tests should now show up in the test explorer, and you should not run into this issue anymore.

References

  1. Link to MSDN reference which explains how to resolve the issue.
answered on Stack Overflow May 15, 2017 by user3613932
3

This is a bit out of my scope, but the configuration settings for both projects are set correctly, right? You have them set to build for AnyCPU or x64?

Just trying to Occam's Razor it out... I know I've been frustrated too many times by configuration settings that VS just magically decides to change on me.

answered on Stack Overflow Aug 1, 2013 by nathas

User contributions licensed under CC BY-SA 3.0