Created
September 19, 2013 06:54
-
-
Save miklund/6619891 to your computer and use it in GitHub Desktop.
MEF Open Generics problem in unit test project.
1. This works if run in a console exe project
2. Does not work if you run through nunit-console(-x86).exe
3. Does not work if run through Resharper
4. Works! if run through Visual Studio test runner (!) Could someone smarter than me figure this out?
Need to reference System.ComponentModel.Compositi…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Test | |
{ | |
using System.ComponentModel.Composition; | |
using System.ComponentModel.Composition.Hosting; | |
using System.Linq; | |
using NUnit.Framework; | |
[Export] | |
public class Class0 | |
{ | |
} | |
[Export] | |
public class Class1<T> | |
{ | |
} | |
[TestFixture] | |
public class TestClass1 | |
{ | |
[Test] | |
public void ShouldResolve() | |
{ | |
var typeCatalog1 = new TypeCatalog(typeof(Class0)); | |
var typeParts1 = typeCatalog1.Parts.ToArray(); | |
Assert.That(typeParts1.Count(), Is.GreaterThan(0), "Expected Class0 to be in TypeCatalog"); | |
var typeCatalog2 = new TypeCatalog(typeof(Class1<>)); | |
var typeParts2 = typeCatalog2.Parts.ToArray(); | |
Assert.That(typeParts2.Count(), Is.GreaterThan(0), "Expected Class1 to be in TypeCatalog"); | |
} | |
} | |
} |
Anyone has a clue on this?
I ran into this too and also loading assemblies into PowerShell, the workaround was (presumably not needed with some future releases):
//Resharper test runner fix due to MEF open generic export fix requiring .NET 4.5.1 vs. some hard-coded Framework version check...
const string v45TargetFrameworkName = ".NETFramework,Version=v4.5";
var fusionStoreField = typeof(AppDomain).GetField("_FusionStore", System.Reflection.BindingFlags.NonPublic |System.Reflection.BindingFlags.Instance);
var fusionStore = (AppDomainSetup)(fusionStoreField.GetValue(AppDomain.CurrentDomain));
if (fusionStore.TargetFrameworkName != v45TargetFrameworkName)
fusionStore.TargetFrameworkName = v45TargetFrameworkName;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have the same problem. Any luck on investigating why is it happening?