nunit3-vs-adapter: 4.4.0 breaking change for TestAssemblyLoadContext
Looks like it may be specific to roslyn generated types:
System.InvalidCastException : [A]Microsoft.CodeAnalysis.Scripting.Hosting.CommandLineScriptGlobals cannot be cast to [B]Microsoft.CodeAnalysis.Scripting.Hosting.CommandLineScriptGlobals. Type A originates from 'Microsoft.CodeAnalysis.Scripting, Version=3.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context '"" NUnit.Engine.Internal.TestAssemblyLoadContext #2' at location '/alloy-test/AlloyEngineTest/bin/x64/Debug/net7.0/Microsoft.CodeAnalysis.Scripting.dll'. Type B originates from 'Microsoft.CodeAnalysis.Scripting, Version=3.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location '/alloy-test/AlloyEngineTest/bin/x64/Debug/net7.0/Microsoft.CodeAnalysis.Scripting.dll'.
When reporting a bug, please provide the following information to speed up triage:
- NUnit and NUnit3TestAdapter versions: 4.4.0 / 17.5.0
- Visual Studio edition and full version number (see Help About): Pro 17.4.4 (but error is on dotnet test command without VS installed)
- A short repro, preferably attached or pointing to a git repo or gist: Looks like an object passed to a
Scriptexecution that comes from the test load context, while the script was compiled in the Default context. - What .net platform and version is being targeted: 7
- If TFS/VSTS issue, what version, hosted or on-premises, and what build task you see this in: it’s
dotnet testrunning inside a docker container mcr.microsoft.com/dotnet/sdk:7.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 3
- Comments: 32 (17 by maintainers)
Commits related to this issue
- Fixes for issues #1065 and #1066 — committed to nunit/nunit3-vs-adapter by OsirisTerje a year ago
- Fix for the adapter issues 1065 and 1066 — committed to nunit/nunit-console by OsirisTerje a year ago
- Enginefix (#1071) * minor fixes to nuspec and update package for acceptance * Fixes for issues #1065 and #1066 * updated version * removed local feed — committed to nunit/nunit3-vs-adapter by OsirisTerje a year ago
- Enginefix (#1072) * minor fixes to nuspec and update package for acceptance * Fixes for issues #1065 and #1066 * updated version * removed local feed * updated to 4.4.2, removed refs to d... — committed to nunit/nunit3-vs-adapter by OsirisTerje a year ago
- Enginefix (#1073) * minor fixes to nuspec and update package for acceptance * Fixes for issues #1065 and #1066 * updated version * removed local feed * updated to 4.4.2, removed refs to d... — committed to nunit/nunit3-vs-adapter by OsirisTerje a year ago
- Enginefix (#1074) * minor fixes to nuspec and update package for acceptance * Fixes for issues #1065 and #1066 * updated version * removed local feed * updated to 4.4.2, removed refs to d... — committed to nunit/nunit3-vs-adapter by OsirisTerje a year ago
@OsirisTerje should 4.4 be unlisted? it broke approx 50% of projects i used it on
Hotfix version 4.4.2, nearly identical to the alpha version attached yesterday, is now released. The difference from the attached version is that the Microsoft.Extensions.DependencyModel is not include in the adapter package. It is not needed there, so it was removed. The release notes is here https://docs.nunit.org/articles/vs-test-adapter/AdapterV4-Release-Notes.html (includes some more explanations) and the package is uploaded to nuget https://www.nuget.org/packages/NUnit3TestAdapter/4.4.2. Thanks, everyone for reporting and providing repros!
@SimonCropp @gregsdennis Ok, Ok, you guys win! It’s unlisted!!
v4.4.2 is working thanks!
@Methuselah96 @dave-yotta @daviddenis-stx @paulhickman-a365 Please find attached an alpha version of 4.4.1-alpha.1 and a nuget config file. The alpha version works now on @paulhickman-a365’s repro. Can you all please verify that it also works on your solutions? This alpha uses the 3.15.2 engine, but extended as a 3.15.3-dev engine with added support for .net 8. That is a “Point in time” where I am pretty sure we have a stable version. It will thus not have the fixes that are in the 3.16.X engine, but looking through the issues there I think it will work. The 4.3.1 adapter is based on 3.15.2 engine.
I suggest you add the package to a c:\nuget folder locally, and then add the nuget.config (in the nuget.zip file) to your solution, so that the package is found there.
NUnit3TestAdapter.4.4.1-alpha.1.zip nuget.zip
@daviddenis-stx Yes, I think that’s where it happens, and you see that the MS package was introduced there.
Sorry, Software Factory. Upgrading the nuget package made the factory unit tests go red in any part using some degree of reflection 😃 NUnit3TestAdapter 4.3.1 green results, NUnit3TestAdapter 4.4.0 red results.
It fails in the region below, basically we just created an instance of something using type lookup, then calling the constructor (the instance is created correctly, that is it finds the assembly, the constructor, and invokes it nicely). Then it tries to cast the received “object” to T and fails with InvalidCastException. For example an instance of class MyThing : IMyThing will fail on the cast line, throwing an exception “Cannot cast to IMyThing”. I suspect there’s something weird with the reflexive loading of assemblies and the loading of types in 4.4.0 ?