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.

CodeWarrior
  • 7,388
  • 7
  • 51
  • 78
  • Perhaps a stupid question, but are you sure that these are the selected `Settings` for your test run? – chaliasos Jul 18 '13 at 06:29
  • Yup. The path menuitem under the Test menu that corresponds with that file has a check mark next to it. – CodeWarrior Jul 18 '13 at 14:31
  • they fixed this in 2012. There is a 64-bit test host. Like other said you can use corflags to remove the 32-bit only flag from mstest and then there are some license registry setting that need to be copied from wow registry node, and set the executionhost to msil. In my group we could not add the registry settings to build machines so I wrote a little app that generates a proxy assembly with test metadata and stubs for tests, when the tests are executed the proxy loads the test dlls and executes the actual tests – user1985513 Jul 31 '13 at 21:46
  • If the prescribed way of achieving it is to remove the 32bit flag from MSTest and goof around in the registry and whatnot, then I would say that it is definitely not fixed in 2012. While you can *force* it to work, that does not mean that it is fixed. I have spent way too much time on this already, but I may have some more cycles to pay to it later on. For now, I contend that it is broke as ever. Once Microsoft gets it to a state where it takes the settings and acts on them without having to hack at MSTest, then I will agree. – CodeWarrior Aug 04 '13 at 05:30

3 Answers3

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

9

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.
user3613932
  • 1,219
  • 15
  • 16
  • Thank you for your answer. What version of Visual Studio are you using there? At the time that I posted this question I was using Visual Studio 2012. I have never circled back to this issue (I have actually changed jobs three times since then!) so hopefully Microsoft have fully implemented x64 support for testing rather than just saying it was done when in fact it was not. – CodeWarrior May 16 '17 at 02:44
  • 2
    I am using Visual Studio 2015. – user3613932 May 16 '17 at 19:38
  • Alright good to know. MSTest can run tests in 64-bit in VS 2015. Thanks! – CodeWarrior May 17 '17 at 20:55
  • I think this only works through the IDE. When I try to run MSTest.exe at the command line, it complains that the DLL is the wrong format. I think that MSTest is actually a 32bit app. – Christian Findlay Apr 02 '19 at 06:08
  • You are right; I have only tested this through the IDE. Please feel free to change the answer if you find the right fix for command line. – user3613932 Apr 03 '19 at 01:54
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.

nathas
  • 949
  • 1
  • 9
  • 15