Unable to set TestContext property for my class (.NET Compact Framework)

Suppose you’re using Visual Studio 2008 and you’ve just found out that Microsoft added unit test support for the Compact Framework on devices and emulators. Neat-o!

So you add one to your project thinking, this’ll be fantastic.

Then it doesn’t work.

You get the following cryptic error:

Unable to set TestContext property for the class {class}. Error:  System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'

“So,” you think, “I obviously did something wrong, but it’s not apparent to me what I did. I will check the Google.”

But Google only shows you what to do for the full framework.The answer for the full framework is to delete your reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework, then search for it again in the Add Reference dialog. Microsoft forgot to update all the project templates for VS08, so all of the esoteric projects point to the assemblies for VS 2005. Quality tool, my ass. The full framework instructions don’t make any sense for your awesome Compact Framework assembly. Uh oh, now what are you going to do?

Maybe it’s your project that’s screwed up. So you start a new one to see if it works. It doesn’t, but you get a different error: References root node unavailable. You might as well search the google for that one and then you get this forum post that repeats the solution over and over:

Restart the IDE.

You figure it can’t hurt, so you try it.

And it works.

You can now use unit tests for .NET CF projects, but you’re no longer smiling about it.

2 Replies to “Unable to set TestContext property for my class (.NET Compact Framework)”

  1. I also found that following these instructions proved to be useful:

    http://msdn.microsoft.com/en-us/library/bb384146.aspx

    In short: these were the crucial steps:

    1. Double-click the file that is named SmartDeviceTestRun.testrunConfig in Solution Explorer.

    2. Click Hosts.

    3. Verify that Host type is set to Smart Device, Platform is set to Pocket PC 2003, and Device is set to Pocket PC 2003 SE Emulator.

  2. I’m having the same issue with a VS2008 application for mobile devices, I could not find the test config file, the restart of the IDE did not work

Comments are closed.