-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NUnit.Engine 3.12.0 .NET Core and TypeDescriptor.GetConverter([...]) dependency loading problems #916
Comments
Any update on this please ? |
Hi @Learfin, @joeltankam, @VoltanFr, @bouchraRekhadda - believe you're all seeing manifestations of #828. That issue essentially is just waiting for someone to pick it up and investigate - we'd love some help, if you'd be willing? 🙂 |
Hello @ChrisMaddock thank you for your feedback. It seems like I've missed the issue you are referring to 😅. |
Great - thanks @bouchraRekhadda! Just digging into this now myself too...actually think #937 may help too, which is good news cc @CharliePoole |
@ChrisMaddock Thanks a lot for #942 |
Hi @joeltankam - I'm not sure on this, but I believe the Custom Assembly Load Context is currently required to allow engine to locate the correct version of the framework assembly that a test assembly depends on. By all means feel free to dig in - if there's a way of it working without this and sufficient justification to do so, more than happy to consider it.
Out of interest - what case do you have where using the default load context is preferable? |
In .NET Core, NUnit.Engine 3.12.0 causes some problems when the tested code calls TypeDescriptor.GetConverter([...]).
For info, TypeDescriptor.GetConverter([...]) is used by JSonConvert.SerializeObject([...]) (from NewtonSoft.Json).
I use the following code for my tests:
Problem 1 - Failure in NUnit.ConsoleRunner.NetCore (version 3.12.0-beta2)
For this test, the code above is compiled with the following csproj (created with dotnet test):
The test passes in Visual Studio, Rider and dotnet test, but fails in NUnit.ConsoleRunner.NetCore (version 3.12.0-beta2):
Problem 2 - Failure when the tested code depends on NUnit.Engine 3.12.0
For this test, the code above is compiled with the following csproj (same as problem 1 with a new dependency to NUnit.Engine 3.12.0):
The test fails in Visual Studio, Rider and dotnet test:
The failure is linked to the usage of AssemblyLoadContext in NUnit.Engine 3.12.0: MyClass type's assembly is loaded in the Default AssemblyLoadContext and in the NUnit custom AssemblyLoadContext. At runtime, the type of the parameter value passed to MyClassTypeConverter.ConvertTo([...]) comes from the assembly loaded in the NUnit custom AssemblyLoadContext whereas the (MyClass) type used to cast comes from the assembly loaded in the Default AssemblLoadContext. The cast fails because types loaded in two AssemblyLoadContext are not the same.
Forcing the usage of the NUnit custom AssemblyLoadContext by calling the following line before the test execution makes it pass:
I can add this line in the static constructor of a SetUpFixture class to setup it once for all, but I have to do this hack in each test project, and this is not very clean.
Note that with NUnit.ConsoleRunner.NetCore (version 3.12.0-beta2), the cast works (without the hack mentioned above) but there is the same failure as described in problem 1.
For info, we depend on NUnit.Engine 3.12.0 in our homemade unit test runner to be able to launch .NET Core unit tests (we need this fix).
The text was updated successfully, but these errors were encountered: