C# – What does “Method …ClassInitialize has wrong signature …” mean

cruntime-errorunit testingvisual studio 2012

In my Visual Studio 2012 solution I have a C# project for unit testing C++/CLI code, e.g.

...
using System.IO;
using Stuff;

namespace MyCLIClassTest
{
    [TestClass]
    public class MyCLIClassTest
    {
        public MyCLIClassTest() {}

        [ClassInitialize]
        public static void Setup(TestContext testContext) 
        {
        }

        [TestMethod]
        public void LibraryAccessTest()
        {
            ...
        }
    }
}

Now, the C# tests all fail with a message like "Method MyCLIClassTest.MyCLIClassTest.ClassInitialize has wrong signature. The method must be static, public, does not return a value and should take a single parameter of type TestContext."

After removing the ClassInitializer I got "Unable to set TestContext property for the class MyCLIClassTest.MyCLIClassTest. Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestContextImplementation' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'..

Best Answer

I used DLLs of older unit testing framework versions. This happened because the project migrated recently to VS2012.

So, in the solution explorer under the test project you find "References". Right click it and select "Add reference..." to open the Reference Manager. Search for "unittest" and check the Microsoft.VisualStudio.QualityTools.UnitTestFramework with version number 10.1.0.0. Un-check all other versions of this assembly. Close the manager by clicking OK.

enter image description here

Related Topic