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

Unable to load DLL 'wpfgfx_cor3.dll' or one of its dependencies - when run through nunit console (.NET6) #1319

Closed
nickkfwong opened this issue Feb 13, 2023 · 13 comments

Comments

@nickkfwong
Copy link

Hello,
Previously I have raised this issue to the wpf team, regarding running wpf tests on nunit console. (since initially i think it was kind of related to framework dll loading)

But after some thought, since
dotnet test <test.dll> works
but
nunit3-console.exe <test.dll> does not,

I started to suspect it might also be some hidden issue in the console itself rather than the framework itself?
(as dotnet test still relies on the core nunit engine, which prove the engine itself is not a problem?)

I have included all the info I have investigated so far, and a sample project in that issue .

Meanwhile, may I see if anyone might have faced this/have some insight on this issue?
Many thanks for your time.

Note:

  • I am seeing this when migrating a .NET4.8 project to a .NET6 project. This issue is not seen when the project is at .NET4.8.
  • All nunit are installed through nuget
  • inprocess flag - the test cant run with error:

NUnit.Engine.NUnitEngineException : The NUnit 3 driver encountered an error while executing reflected code.
----> System.InvalidCastException : Unable to cast transparent proxy to type 'System.Web.UI.ICallbackEventHandler'.

@CharliePoole
Copy link
Member

@nickkfwong Re the last point... You can't run a .NET 6.0 test in-process because the console process is running under the .NET Framework.

@nickkfwong
Copy link
Author

nickkfwong commented Feb 14, 2023

@nickkfwong Re the last point... You can't run a .NET 6.0 test in-process because the console process is running under the .NET Framework.

I see understood - I just tried to list out as the template says that might be helpful for troubleshoot. Indeed, I had tried various options I can see from the help menu, but seems none of them can twist the behavior to workaround the problem ;-(

@svg2003
Copy link
Contributor

svg2003 commented Feb 14, 2023

@nickkfwong,

you can try to change nunit-agent.runtimeconfig.json for net6 agent as following:

{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.WindowsDesktop.App",
"version": "6.0.0"
}
}
}

@nickkfwong
Copy link
Author

@nickkfwong,

you can try to change nunit-agent.runtimeconfig.json for net6 agent as following:

{ "runtimeOptions": { "tfm": "net6.0", "framework": { "name": "Microsoft.WindowsDesktop.App", "version": "6.0.0" } } }

Oh my god! This indeed fixes the problem in my test project. I will further check the same in my actual bigger project. Big thanks @svg2003 for pointing this out!

Meanwhile, since this comes with the nuget package, what will be the general strategy to have such a modified runtime config to be used in a CI setup? (For this test project I use project specified package path for easier path reference. But usually we use the global path. I believe I should not expect myself to modify anything inside the packages folder?)

Also curious if that is a known framework behavior (or is it a nunit console behavior?)...since some other desktop dlls like PresentationCore can be picked up without issue..? (or they do have issue?)

@svg2003
Copy link
Contributor

svg2003 commented Feb 15, 2023

@nickkfwong ,

Sorry, but I have no idea how it supposed to be. I recently switched huge project from net472 to net6, so it's just one of my observations and workarounds. We're using static files during the build, for such things like test runners, so it works for us, albeit, certainly, I'd prefer don't touch official package and pass runtime config explicitly

@nickkfwong
Copy link
Author

@nickkfwong ,

Sorry, but I have no idea how it supposed to be. I recently switched huge project from net472 to net6, so it's just one of my observations and workarounds. We're using static files during the build, for such things like test runners, so it works for us, albeit, certainly, I'd prefer don't touch official package and pass runtime config explicitly

@svg2003 Thank you for the advice!
May I ask which option allow us to pass runtime config explicitly? (just tried --configfile but doesnt seem so..?)
or do you mean to copy the tools folder (with tools\agent), then override the runtime config in tools/agent, then point our project to use that copied tools folder?

@svg2003
Copy link
Contributor

svg2003 commented Feb 15, 2023

@nickkfwong ,

From what I know, there is no such option right now. I'd expect something like --runtimeConfig parameter for nunit-console.exe that would be passed to agent.
For now - I just overwrote existing config. It works for us.

@nickkfwong
Copy link
Author

BTW - when I look into the runtime config of my test project, it is something like this:

"frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "6.0.0"
      }
    ]

Does it mean it would be better to have the agent having the same config also?
Or else, would that be possible for nunit to obey the runtime config of the test dll? (probably cant unless some magic merge happens?)

@svg2003
Copy link
Contributor

svg2003 commented Feb 15, 2023

For you it's probably has no sense, if you're going to use windows anyway.
For nunit - I'd say, more realistically, unless you would do this change yourself.

@CharliePoole
Copy link
Member

@nickkfwong In an earlier release of the engine (1 or 2 releases ago) I did something similar to what you suggest. It created a bug where tests could not be run on a machine without windows forms installed. So any change to the agent runtime config has to allow for that use case, which happens in embedded applications.

@svg2003
Copy link
Contributor

svg2003 commented Feb 15, 2023

Btw, @CharliePoole , are you OK if I will add --runtimeconfig and --depsfile option for console runner, so it could forward it to agent?
Also, (might be as another PR) probably make sense to check these files for test.dll and add them automatically, if they are not specified explicitly.

@nickkfwong
Copy link
Author

@svg2003 @CharliePoole Understood - thanks for all the advices. I will take @svg2003 's workaround to proceed my migration project for now ;-p

Happy to help out if there is anything needed.

@nickkfwong
Copy link
Author

Close for now after clarification.

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

No branches or pull requests

3 participants