-
Notifications
You must be signed in to change notification settings - Fork 152
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
PlatformNotSupportedException when testing a .NET Standard assembly with reference to System.Data.SqlClient #1282
Comments
As you reference the Nunit3Adapter you don't need to install the nunit.console tool and can use |
@manfred-brands Just tested running |
You can output to nunit3 format with |
Yep that should do it. I still think the original issue might be worth looking into, though. |
I agree. We need to compare the loading in nunit.console with the one from the adapter. |
This could be related to or duplicating #1269 |
interesting.
when targeting NUnit.Engine 3.15.2 then
when targeting NUnit.Engine 3.16.2 then
|
is always the stub assembly that throws for most methods with NotSupported |
perhaps the problem is a combo of this dotnet/SqlClient#1687 and the fact that we now use AssemblyLoadContext https://github.com/nunit/nunit-console/blob/76330acce7d36db94e3acc03667e608b0f4858cc/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyLoadContext.cs |
is TestAssemblyLoadContext missing a call to TestAssemblyResolver.OnResolving so it can interrogate _dependencyContext.RuntimeLibraries ? |
Someone with in-depth knowledge of SqlClient will probably need to look at this. |
@CharliePoole i debugged into it and OnResolving was never hit for the sql dll |
I'm guessing that's because it's in the base directory, but I'm really not sure. Can you see what happens if you remove it at execution time? |
I'm seeing exactly this problem attempting to use System.IO.Ports (I know....) in a .Net 7.0 assembly with the NUnit3 console runner. The windows runtime assembly is never loaded, and we get the "System.PlatformNotSupportedException : System.IO.Ports is currently only supported on Windows." error from the stub assembly. |
If it helps other people arriving from Google; upgrading from Cheers, |
Hello,
As the title suggests we faced an issue when trying to unit test a .NET Standard assembly which transitively references System.Data.SqlClient.
Steps to reproduce:
1.1 Create an empty solution and a new .NET Standard project using Visual Studio
1.2 Add a package reference to System.Data.SqlClient, version 4.6.1 in the project's .csproj file
1.3 Create a public method which simply opens a new SqlConnection to a local database
2.1 Create a .NET 6 project using visual studio
2.2 Add a package a package reference to NUnit, version 3.7.1, Microsoft.NET.Test.SDK, version 17.4.0 and NUnit3TestAdapter, version 3.15.1
2.3 Add a project reference to the the project created in 1.
2.4 Create a test method, mark it with a
[Test]
attribute and invoke the method from the .NET Standard library created in 1.3dotnet tool install --local "NUnit.ConsoleRunner.NetCore" --version "3.16.1-dev00002"
dotnet nunit {PROJECT_NAME}.Tests.dll
Probable cause: The .NET Standard 2.0 assembly System.Data.SqlClient which is built and located directly under /bin is simply a placeholder assembly which throws
PlatformNotSupportedException
in every public method that it exposes. The reason for this is that the implementation of System.Data.SqlClient is platform-specific and because of that, the runtime must locate this platform-specific implementation during the runtime of the program. This is usually not a problem, since this information is located in the {project_directory}.Tests.deps.json file, which the runtime uses to locate the concrete implementation of System.Data.SqlClient.If we add the following lines anywhere in our test:
we can see that the output when the test is ran via Visual Studio and with the nunit console is different.
For Visual Studio it will be similar to the following:
For the nunit console it will be similar to:
As we can see in the second output there's no reference to TestProject.Tests.deps.json which actually contains the information on how to load the correct version of the System.Data.SqlClient assembly during runtime
Is there a workaround around this issue?
The text was updated successfully, but these errors were encountered: