This documentation is archived and is not being maintained.

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.

NoteNote

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

  1. Right-click the solution and then click Properties.

    The Solution Property Pages dialog box is displayed.

  2. Under Configuration Properties, click Configuration.

  3. Click Configuration Manager.

    The Configuration Manager dialog box is displayed.

  4. Under Active solution platform, click New.

    The New Solution Platform dialog box is displayed.

  5. Under Type or select the new platform, click x86.

  6. In the New Solution Platform dialog box, click OK.

  7. In the dialog box that asks whether you want to save changes, click Yes.

  8. On the Configuration Manager dialog box, under Active solution platform, make sure that x86 is selected, and then click Close.

  9. On the Solution Property Pages dialog box, click OK.

Instrument the Application that Loads the Production-Code Binary File

Use this procedure to instrument an intermediary application, or test harness, that your generic test wraps. This intermediary application runs the code that you want to test. This forces that application to run in 32-bit mode.

NoteNote

This procedure will work only if the symbols file is available for the file you are instrumenting.

To specify the executable file for instrumentation

  1. In Visual Studio, open the test project that contains your generic test.

  2. In Solution Explorer, open the Solution Items folder.

  3. In the Solution Items folder, double-click the .testrunconfig file.

  4. The test run configuration dialog box is displayed.

  5. Click Code Coverage.

  6. Under Select artifacts to instrument, select the intermediary application that runs your production-code binary file.

    NoteNote

    If the binary file of the intermediary application is not displayed under Select artifacts to instrument, click Add Assembly. In the Choose Assemblies to Instrument dialog box, specify the file and then click Open.

  7. Click Apply, and then click Close.

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.

NoteNote

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

  1. 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.

  2. Click the Build tab.

  3. For Platform target, specify x86.

  4. On the File menu, click Save Selected Items.

Show: