Skip to content
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

Cannot execute .NET 8 tests that require the Desktop or ASP.NET runtime #1383

Closed
mlessmann opened this issue Jan 15, 2024 · 15 comments · Fixed by #1482
Closed

Cannot execute .NET 8 tests that require the Desktop or ASP.NET runtime #1383

mlessmann opened this issue Jan 15, 2024 · 15 comments · Fixed by #1482
Assignees
Labels
Milestone

Comments

@mlessmann
Copy link

mlessmann commented Jan 15, 2024

Executing a .NET 8 test assembly that references types from WinForms, WPF, or ASP.NET results in the following (or similar) exception:
Could not load file or assembly 'System.Windows.Forms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e89'. The system cannot find the file specified.

The reason is that the nunit-agent only references the Microsoft.NETCore.App runtime in its runtimeconfig.json. Therefore a workaround is to manually add the missing runtimes (Microsoft.WindowsDesktop.App and/or Microsoft.AspNetCore.App) to the runtimeconfig.json.

As far as I know adding the WindowsDesktop runtime will lead to the agent no longer working on Linux. Ideally we could load the necessary runtimes dynamically depending on what dependencies the test assembly has, though I have no idea if that is even possible. The Microsoft documentation does not sound promising.

@ilCosmico
Copy link

ilCosmico commented Feb 13, 2024

The error occurs when the Microsoft.Windows.Compatibility package is added to the project.

Here is a repro
NUnitTestProject1.zip

@ilCosmico
Copy link

@OsirisTerje Any news on this?

@OsirisTerje
Copy link
Member

@ilCosmico No, we don't have anyone working here at the moment.

@CharliePoole
Copy link
Collaborator

@mlessmann Although some other people have referenced this with respect to the NETCORE console runner, it's not clear from your report that you are using it, as opposed to the standard console runner. Can you clarify what package you have installed? It would also help to see the command line you are using to run your tests.

@andrewimcclement
Copy link

Can this be closed as a duplicate of #1203? (Though the fix still isn't generally available, only on the 3.18 dev build or 4.0)

@OsirisTerje
Copy link
Member

@andrewimcclement The 3.18.1 is out. Have you checked it works with that?

@CharliePoole
Copy link
Collaborator

I examined this and didn't close it with 3.18.1 because we are still waiting for info. I wouldn't want to close it since some people may be running the standard console and others the .NET Core console, which are essentially two different programs due to our use of conditional compilation. I'll look at this when I come back to work in a few weeks.

@ilCosmico
Copy link

@andrewimcclement The 3.18.1 is out. Have you checked it works with that?

I tried the sample project NUnitTestProject1.zip and it works with version 3.18.1 🥳

image

@CharliePoole
Copy link
Collaborator

I'll add a version of NUnitTestProject1.zip to the package tests when I'm back to work.

@dipts
Copy link

dipts commented Aug 3, 2024

I have also tested the project with 3.18.1, it works when targeting WindowsForms. However, if I switch the project to WPF, it still does not run the test. I think it loads Windows.Base from the .Net Framework instead of the .Net 8 WindowsDesktopApp runtime.

image
NUnitTestProjectWPF.zip

@CharliePoole
Copy link
Collaborator

Can someone experiencing this error try the latest build on our MyGet feed? That one is running .NET 8.0 WPF apps for me and finding the correct WindowsBase. The latest version on myget is 2.0.0-dev00027.

@dipts
Copy link

dipts commented Sep 15, 2024

I'm sorry, still the same error with the WPF test project. Identical screenshot except for the NUnit Console version.

I have tested version 3.18.2-dev00027, I assume you mean this one. Is there anything else that needs to be changed in the project?

@CharliePoole
Copy link
Collaborator

@dipts Thanks for checking. Yes, that's the version. I'm jumping back and forth between two projects and mixed up the versions. So, this bug remains on the list. It's a matter of not taking the first WindowsBase assembly found but continuing to examine others and taking the best version.

@CharliePoole
Copy link
Collaborator

This issue has been resolved in version 3.18.2

The release is available on:
GitHub.
NuGet packages are also available NuGet.org and
Chocolatey Packages may be found at Chocolatey.org

@dipts
Copy link

dipts commented Sep 21, 2024

@CharliePoole Thanks for the fix, it solves the error message that WindowsBase is not found. Unfortunately, the WPF tests do not run again, but get stuck on another module that cannot be loaded, this time wpfgfx_cor3.dll. I know that there are already a few old issues about this - but I cannot derive any solution from them. I assume that the difference lies in the fact that wpfgfx_cor3.dll is a native DLL - and therefore does not run via the AssemblyResolver.

image

However, testing WPF projects is not yet possible again with 3.18.2.

I have extended the WPF repro project: NUnitTestProjectWPF2.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants