{"action":"created","issue":{"url":"https://api.github.com/repos/xunit/xunit/issues/355","labels_url":"https://api.github.com/repos/xunit/xunit/issues/355/labels{/name}","comments_url":"https://api.github.com/repos/xunit/xunit/issues/355/comments","events_url":"https://api.github.com/repos/xunit/xunit/issues/355/events","html_url":"https://github.com/xunit/xunit/issues/355","id":62484714,"number":355,"title":"Collection Fixture tests fails on project references the VS Runner","user":{"login":"janhartmann","id":1107383,"avatar_url":"https://avatars.githubusercontent.com/u/1107383?v=3","gravatar_id":"","url":"https://api.github.com/users/janhartmann","html_url":"https://github.com/janhartmann","followers_url":"https://api.github.com/users/janhartmann/followers","following_url":"https://api.github.com/users/janhartmann/following{/other_user}","gists_url":"https://api.github.com/users/janhartmann/gists{/gist_id}","starred_url":"https://api.github.com/users/janhartmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janhartmann/subscriptions","organizations_url":"https://api.github.com/users/janhartmann/orgs","repos_url":"https://api.github.com/users/janhartmann/repos","events_url":"https://api.github.com/users/janhartmann/events{/privacy}","received_events_url":"https://api.github.com/users/janhartmann/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-17T18:55:42Z","updated_at":"2015-03-17T19:05:46Z","closed_at":"2015-03-17T19:05:46Z","body":"First of all, great work on this library.\r\n\r\nI have been using `2.0.0-rc1-build2826` until today where I have upgraded all my xUnit packages to the stable `2.0.0`. But I have run into a weird problem with a test assembly that references the VS Runner. Surprisingly, other test assemblies using the same method as below runs just fine. \r\n\r\nOk, let's get to it... I have lot of test where I test the composition root of my application (everything wired probably, IoC works etc.) and in order to speed up that progress I set up the fixture like so:\r\n\r\n```cs\r\n// NerveFramework.UnitTests (This assembly has the xunit.runner.visualstudio package)\r\npublic class CompositionRootFixture\r\n{\r\n\tpublic Container Container { get; private set; }\r\n\r\n\tpublic CompositionRootFixture()\r\n\t{\r\n\t\tContainer = new Container();\r\n\t\tvar assemblies = new[] { Assembly.GetExecutingAssembly() };\r\n\r\n\t\tContainer.RegisterNerveFramework(settings =>\r\n\t\t{\r\n\t\t\tsettings.EventAssemblies = assemblies;\r\n\t\t\tsettings.FluentValidationAssemblies = assemblies;\r\n\t\t\tsettings.TransactionAssemblies = assemblies;\r\n\t\t});\r\n\t\t\r\n\t}\r\n\r\n}\r\n\r\n[CollectionDefinition(\"Simple Injector Tests\")]\r\npublic class SimpleInjectorTests : ICollectionFixture<CompositionRootFixture>\r\n{\r\n\t// This class has no code, and is never created. Its purpose is simply\r\n\t// to be the place to apply [CollectionDefinition] and all the\r\n\t// ICollectionFixture<> interfaces.\r\n}\r\n```` \r\n\r\nAnd all my tests classes (in the same assembly) using this fixture looks like this:\r\n\r\n```cs\r\n[Collection(\"Simple Injector Tests\")]\r\npublic class CompositionRootTests\r\n{\r\n\tprivate readonly CompositionRootFixture _fixture;\r\n\r\n\tpublic CompositionRootTests(CompositionRootFixture fixture)\r\n\t{\r\n\t\t_fixture = fixture;\r\n\t}\r\n\r\n\t[Fact]\r\n\tpublic void CompositionRoot_ComposesVerifiedRoot_WithoutDiagnosticsWarnings()\r\n\t{\r\n\t\t_fixture.Container.Verify();\r\n\t\tvar results = Analyzer.Analyze(_fixture.Container);\r\n\r\n\t\tAssert.False(results.Any());\r\n\t}\r\n}\r\n```\r\n\r\nAll these test fails with the following message (in danish, sorry - anyone let me know how I can get the english translation, thanks.)\r\n\r\n```\r\nTest Name:\tNerveFramework.UnitTests.Infrastructure.CompositionRoot.CompositionRootTests.CompositionRoot_AllowsOverridingRegistrations\r\nTest FullName:\tNerveFramework.UnitTests.Infrastructure.CompositionRoot.CompositionRootTests.CompositionRoot_AllowsOverridingRegistrations\r\nTest Source:\tc:\\GitHub\\nerve-framework\\NerveFramework.UnitTests\\Infrastructure\\CompositionRoot\\CompositionRootTests.cs : line 28\r\nTest Outcome:\tFailed\r\nTest Duration:\t0:00:00,001\r\n\r\nResult Message:\t\r\nSystem.AggregateException : Der opstod en eller flere fejl.\r\n---- System.Reflection.ReflectionTypeLoadException : En eller flere af de anmodede typer kan ikke indlæses. Hent egenskaben LoaderExceptions for at få flere oplysninger.\r\n---- The following constructor parameters did not have matching fixture data: CompositionRootFixture fixture\r\nResult StackTrace:\t\r\n----- Inner Stack Trace #1 (System.Reflection.ReflectionTypeLoadException) -----\r\n   ved System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\r\n   ved System.Reflection.RuntimeModule.GetTypes()\r\n   ved System.Reflection.Assembly.GetTypes()\r\n   ved NerveFramework.Infrastructure.CompositionRoot.ContainerExtensions.<RegisterNerveFrameworkPackages>b__5(Assembly assembly) i c:\\GitHub\\nerve-framework\\NerveFramework\\Infrastructure\\CompositionRoot\\ContainerExtensions.cs:linje 38\r\n   ved System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()\r\n   ved System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n   ved System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   ved System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   ved NerveFramework.Infrastructure.CompositionRoot.ContainerExtensions.RegisterNerveFrameworkPackages(Container container, CompositionRootSettings settings) i c:\\GitHub\\nerve-framework\\NerveFramework\\Infrastructure\\CompositionRoot\\ContainerExtensions.cs:linje 43\r\n   ved NerveFramework.Infrastructure.CompositionRoot.ContainerExtensions.RegisterNerveFramework(Container container, Action`1 settings) i c:\\GitHub\\nerve-framework\\NerveFramework\\Infrastructure\\CompositionRoot\\ContainerExtensions.cs:linje 27\r\n   ved NerveFramework.UnitTests.Infrastructure.CompositionRoot.CompositionRootFixture..ctor() i c:\\GitHub\\nerve-framework\\NerveFramework.UnitTests\\Infrastructure\\CompositionRoot\\CompositionRootFixture.cs:linje 17\r\n----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----\r\n```\r\n\r\nWhich boils down to this extension method failing, which is called from the  `container.RegisterNerveFramework(..)` in the `CompositionRootFixture` above.\r\n\r\n```cs\r\npublic static void RegisterNerveFrameworkPackages(this Container container, CompositionRootSettings settings)\r\n{\r\n\t var packages = from assembly in AppDomain.CurrentDomain.GetAssemblies()\r\n\t\t\t\t\tfrom type in assembly.GetTypes()\r\n\t\t\t\t\twhere typeof(INerveFrameworkPackage).IsAssignableFrom(type)\r\n\t\t\t\t\twhere !type.IsAbstract\r\n\t\t\t\t\tselect (INerveFrameworkPackage)Activator.CreateInstance(type);\r\n\r\n\tpackages.ToList().ForEach(p => p.RegisterServices(container, settings));\r\n}\r\n```\r\nI have attached the error where it tries to load the `xunit.runner.visualstudio.testadapter, Version=2.0.0.1050` assembly. This did not happen in the previous beta.\r\n\r\n![xunit-exception](https://cloud.githubusercontent.com/assets/1107383/6695178/7c6f3a4c-ccdf-11e4-9da8-566b07a8f2d8.PNG)\r\n\r\nLet me know if I need to provide any more info, thanks! ;-)\r\n\r\nKind regards,\r\nJan"},"comment":{"url":"https://api.github.com/repos/xunit/xunit/issues/comments/82536200","html_url":"https://github.com/xunit/xunit/issues/355#issuecomment-82536200","issue_url":"https://api.github.com/repos/xunit/xunit/issues/355","id":82536200,"user":{"login":"bradwilson","id":16944,"avatar_url":"https://avatars.githubusercontent.com/u/16944?v=3","gravatar_id":"","url":"https://api.github.com/users/bradwilson","html_url":"https://github.com/bradwilson","followers_url":"https://api.github.com/users/bradwilson/followers","following_url":"https://api.github.com/users/bradwilson/following{/other_user}","gists_url":"https://api.github.com/users/bradwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/bradwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradwilson/subscriptions","organizations_url":"https://api.github.com/users/bradwilson/orgs","repos_url":"https://api.github.com/users/bradwilson/repos","events_url":"https://api.github.com/users/bradwilson/events{/privacy}","received_events_url":"https://api.github.com/users/bradwilson/received_events","type":"User","site_admin":false},"created_at":"2015-03-17T19:05:45Z","updated_at":"2015-03-17T19:05:45Z","body":"There's no guarantee that you can always load all the assemblies in your output folder. Some of the dependencies may be provided by the environment at runtime, as is the case with the Visual Studio runner.\r\n\r\nYou need to wrap a `try`/`catch` around any call to `assembly.GetTypes()` and catch for `ReflectionTypeLoadException`, and instead use the list of loaded types that's in the `Types` property of the exception.\r\n\r\nSince you can't use `try`/`catch` in the middle of LINQ, you'll need to convert the `assembly.GetTypes()` call into a local method which does this logic; f.e.:\r\n\r\n```csharp\r\nfrom assembly in AppDomain.CurrentDomain.GetAssemblies()\r\nfrom type in SafeGetTypesForAssembly(assembly) // ...\r\n\r\nprivate static Type[] SafeGetTypesForAssembly(Assembly assembly)\r\n{\r\n    try\r\n    {\r\n        return assembly.GetTypes();\r\n    }\r\n    catch (ReflectionTypeLoadException ex)\r\n    {\r\n        return ex.Types;\r\n    }\r\n}\r\n```"}}