Troubleshooting Generic Tests
When you run generic tests, you might encounter the following error: Gathering code-coverage data does not work when you run a generic test on a 64-bit platform. To solve this error, use the information in the following section, Circumventing the 32-Bit Limitation.
Code coverage instrumentation works only in 32-bit mode, not in 64-bit mode. This is because an assembly can only be loaded in 32-bit mode after it has been instrumented for code coverage.
No such limitation applies when you run unit tests on a 64-bit computer if you are not gathering code-coverage data. This is because VSTestHost.exe, the test engine that loads the class library, runs in a 32-bit process.
For a generic test, the wrapped application is built against "Any CPU," which on a 64-bit computer is executed as a 64-bit process. When this 64-bit process tries to load a 32-bit assembly, an error occurs. You can solve this problem in one of the following ways.
Use the following method if your generic test directly wraps the binary file into which your production code has been compiled:
Use either of the following two methods if there is a layer between the generic test and the production-code binary file. That is, your generic test wraps an intermediary application as a test harness. This test harness, in turn, runs the production code that you are testing.
Change the Solution Configuration to x86
Change the solution configuration from "Any CPU" to "x86."
To change the solution configuration
Right-click the solution and then click Properties.
The Solution Property Pages dialog box is displayed.
Under Configuration Properties, click Configuration.
Click Configuration Manager.
The Configuration Manager dialog box is displayed.
Under Active solution platform, click New.
The New Solution Platform dialog box is displayed.
Under Type or select the new platform, click x86.
In the New Solution Platform dialog box, click OK.
In the dialog box that asks whether you want to save changes, click Yes.
On the Configuration Manager dialog box, under Active solution platform, make sure that x86 is selected, and then click Close.
On the Solution Property Pages dialog box, click OK.
Change Build Settings for the Application that Loads the Production-Code Binary File
Use this procedure to instrument any intermediary application, or test harness, that your generic test wraps. This intermediary application runs the code that you want to test.
In this procedure, you change the settings for the intermediary application to make it build for the x86 platform.
You can do this only if the wrapped application is built from a project in your solution.
To change the build settings for the wrapped application
In Solution Explorer, right-click the project from which the intermediary application is built, and then click Properties.
This displays a property page for the project.
Click the Build tab.
For Platform target, specify x86.
On the File menu, click Save Selected Items.