Build/Test Issues

InvalidCastException when building assembly containing xunit 2.2 tests for a ASP.NET Core 2.0

Started by distilled on 4,076 views

I have a .NET Core 2.0 project (target .NET Framework 4.7) that contains xunit v2.2 tests for an ASP.NET Core 2.0 project in the same solution. When NCrunch tries to build the project an InvalidCastException gets thrown:


An error occurred while analysing this project after it was built: System.InvalidCastException: Unable to cast object of type 'Xunit.Sdk.ReflectionAssemblyInfo' to type 'Xunit.Abstractions.IAssemblyInfo'.
   at Xunit.AppDomainManager_NoAppDomain.CreateObject[TObject](AssemblyName assemblyName, String typeName, Object[] args)
   at Xunit.Xunit2Discoverer..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, IAssemblyInfo assemblyInfo, String assemblyFileName, String xunitExecutionAssemblyPath, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk)
   at nCrunch.Module.XUnit2.Integration.XUnitTestFrameworkContainer.GetDynamicFramework(FilePath assemblyFilePath, DirectoryPath workingDirectory)
   at nCrunch.Module.XUnit2.Integration.XUnit2DiscoveryEnvironment.<>c__DisplayClass2_0.<FindFrameworkTestsInAssembly>b__1()
   at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
   at nCrunch.Common.PerformanceTracking.PerfTracker.TryTrackActivity(String name, Action activity)
   at nCrunch.Module.XUnit2.Integration.XUnit2DiscoveryEnvironment.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
   at nCrunch.TestExecution.TestFinder..()
   at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
   at nCrunch.TestExecution.TestFinder..()
   at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
   at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, DescribedTestFrameworkDiscoverer[] describedDiscoverers, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
   at nCrunch.TestExecution.RemoteTaskRunner.AnalyseAssembly(DescribedTestFrameworkDiscoverer[] applicableFrameworks, ComponentUniqueName testComponentUniqueName, PerfTracker perfTracker)


I have both "Pre-load all assembly references into test environment" and "Copy referenced assemblies to workspace" set to "true" for the test project.
Hi, thanks for sharing this issue.

See here for more information about this - http://forum.ncrunch.net/yaf_postsm10835_AutoFixture-Warning-Incorrect.aspx#post10835.

This is caused by there being an inconsistent version of xunit.abstractions loaded into your test environment. From v3.9, NCrunch will always try to use the version of xunit.abstractions that corresponds with the version of xunit you're using. This is a difference in behaviour with v3.8, where the version of xunit.abstractions was forced to v2.1 through a binding redirection.

Try removing and reinstating your xunit references. Check that you aren't using other tools that might be referencing different versions of xunit.abstractions.

Post a reply

Log in to reply.