Hey, I've come across some odd behavior where System.ComponentModel.Composition.Hosting.TypeCatalog instances initialized with generic type definitions lose track of their parts when running under NCrunch but not under the normal MSTest runner.
Here's the whole test file,
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
namespace MinimumTypeCatalogIssue
{
[TestClass]
public class UnitTest1
{
public interface TestInterface
{
}
[Export(typeof(TestInterface))]
public class TestA<T> : TestInterface
{
}
[Export(typeof(TestInterface))]
public class TestB<T> : TestInterface
{
}
[TestMethod]
public void TestMethod1()
{
var catalog = new TypeCatalog(typeof(TestA<>), typeof(TestB<>));
Assert.AreNotEqual(0, catalog.Parts.Count());
}
}
}
Any clue on how to work around this one or if it can be fixed?
This looks to be related to the .NET version of the task runner NCrunch is using to execute the test. It appears that Microsoft introduced a fix for the TypeCatalog class in v4.5 of the .NET framework. This means that any environment executing this code with a framework version less than v4.5 will fail to execute it correctly.
I observed the issue in all test runners except for MSTest, which suggests that this is quite a widespread issue. Most test runners continue to work with v4.5 and v4.5.1 code using v4 runners, as the metadata is still the same. It seems you've been unlucky enough to find a point of difference.
Other than changing the way your code works to avoid using TypeCatalog for generic types, I see no way to work around this problem. It will need to be resolved with a code fix to NCrunch. I'll try to get you a fixed build before Christmas.