I have a project that uses both QuickFix.Net and Autofac. One of my xUnit tests creates the container for the application and tries to resolve one of the main service instances. I created this test as a regression test to detect when I forget an Autofac registration.

These tests started failing recently and the weird thing is that they are complaining about a type and an Assembly that I don't think either my code or third party code is referencing. Autofac is failing to instantiate Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.ITestExecutionEnvironmentSpecifier while trying to instantiate a QuickFix.SocketInitiator. I looked at the source on GitHub for the DefaultMessageFactory and see that there is the use of reflection to get the assemblies, but this has been there for a long time, so I don't think it is new.

I think this may have started when I upgraded Visual Studio, but I am not sure. Could this be a bug in Visual Studio 2019?

The test fails whether I run it through Visual Studio proper, or via dotnet test from the command line, so that is what makes me unsure.

If anyone has any insight I would appreciate it.

Edit: Here is some additional Information

  • Framework Target: .Net Core 2.2
  • Visual Studio: 16.3.4 with Resharper Ultimate 2019.2.3
  • Autofac Version: 4.9.0
  • XUnit Framework: 2.4.1

Here are some things I've tried without success:

  • Adding a NuGet reference to the 15.0 Microsoft.VisualStudio.TestPlatform.ObjectModel.dll for my test DLL to see if it would cause it and all of its dependencies to be included at runtime.
  • Upgrading to v16.4 of the same library, this caused a silent failure attempting to run unit tests through ReSharper.
  • Upgrading other dependencies in my project.

Here is the main part of the stack trace:

Autofac.Core.DependencyResolutionException : An exception was thrown while activating MyApp.FixConnector.FixConnectorService -> QuickFix.Transport.SocketInitiator.
---- Autofac.Core.DependencyResolutionException : An exception was thrown while invoking the constructor 'Void .ctor(QuickFix.IApplication, QuickFix.IMessageStoreFactory, QuickFix.SessionSettings, QuickFix.ILogFactory)' on type 'SocketInitiator'.
-------- System.TypeLoadException : Could not load type 'Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.ITestExecutionEnvironmentSpecifier' from assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget) in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 135
   at Autofac.Core.Resolving.InstanceLookup.Execute() in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 83
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in C:\projects\autofac\src\Autofac\Core\Resolving\ResolveOperation.cs:line 131
   at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) in C:\projects\autofac\src\Autofac\Core\Resolving\ResolveOperation.cs:line 84
   at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) in C:\projects\autofac\src\Autofac\ResolutionExtensions.cs:line 1041
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) in C:\projects\autofac\src\Autofac\ResolutionExtensions.cs:line 871
   at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters) in C:\projects\autofac\src\Autofac\ResolutionExtensions.cs:line 300
   at MyApp.Tests.Unit.FixConnector.FixConnectorDependencyInjectionTest.TestBuildContainer(String feedName, String feedEnvironment) in C:\dev\MyApp\MyApp.Tests\Unit\FixConnector\FixConnectorDependencyInjectionTest.cs:line 38
----- Inner Stack Trace -----
   at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() in C:\projects\autofac\src\Autofac\Core\Activators\Reflection\ConstructorParameterBinding.cs:line 137
   at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in C:\projects\autofac\src\Autofac\Core\Activators\Reflection\ReflectionActivator.cs:line 120
   at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget) in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 117
----- Inner Stack Trace -----
   at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
   at System.Reflection.RuntimeAssembly.GetExportedTypes()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at QuickFix.DefaultMessageFactory.GetMessageFactories(IEnumerable`1 assemblies)
   at QuickFix.DefaultMessageFactory..ctor(String defaultApplVerId)
   at QuickFix.AbstractInitiator..ctor(IApplication app, IMessageStoreFactory storeFactory, SessionSettings settings, ILogFactory logFactory, IMessageFactory messageFactory)
   at QuickFix.Transport.SocketInitiator..ctor(IApplication application, IMessageStoreFactory storeFactory, SessionSettings settings, ILogFactory logFactory)
   at lambda_method(Closure , Object[] )
   at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() in C:\projects\autofac\src\Autofac\Core\Activators\Reflection\ConstructorParameterBinding.cs:line 129


0

There are 0 best solutions below