Closed rodrigoramos closed 2 years ago
Possibly related from Microsoft's SQL Client FAQ (emphasis mine):
Why do I get a PlatformNotSupported exception when my application hits a SqlClient method? The Microsoft.Data.SqlClient NuGet package includes a number of DLLs supporting different .NET targets and different runtime platforms. If you are getting a PlatformNotSupported Exception when you don't think you should be, it ultimately means your application is not loading the appropriate DLL. There could be a number of reasons for this. The NuGet package structure and infrastructure around referencing and loading referenced NuGet packages includes logic that allows a package to contain multiple DLLs which implement support for different .NET and platform targets. Meaning a different DLL for .NET Framework, .NET Core, .NET Standard, Windows, Linux, etc. The NuGet infrastructure will automatically reference and load the appropriate DLL based on your application's needs.
If your application loads a DLL from a NuGet package directly, it bypasses all this logic and probably loads the incorrect DLL. The DLL in the NuGet package under lib/netstandard2.0/Microsoft.Data.SqlClient.dll is basically the fallback DLL for any unsupported target and simply throws the PlatformNotSupported exception for any call. This is a nicer exception than what you would otherwise get when running on a platform that does not have a DLL built for it. Ultimately, you want to use the NuGet package reference infrastructure or you would have to implement all this target framework and platform support logic yourself when determining which DLL to load.
Additionally, the NuGet package contains all the dependency information for the SqlClient library and facilitates the downloading and referencing of dependencies. If you reference and load an individual DLL manually, it is up to you to ensure all dependencies are also available to the SqlClient library.
Needs further investigation, but the above suggests that Cake might be loading the netstandard2.0
assembly rather than the assembly for the corresponding TFM of the Cake runner e.g. netcoreapp3.1
Reproducible on OSX using the script above:
Hi,
I will take a look at this and get back to you
indeed there is problem with OSX - I try to find some help - I do not know if it is not connected with the fact that Microsoft.Data.SqlClient do not contain only folder for unix and not for osx - if Cake somewhat does not influence there in WSL2 Ubuntu 20.04 it looks like below
on OSX I receive for simplified sample
this is really hard - I am curious if same thing appear in cake.frosting - if yes then cloning repo of MS.D.SqlClient will be necessary
in frosting there is no problem...
...but :smile: it seems that in cake 1.3.0 it was fixed - can you please force upgrade to 1.3.0?
this is from my machine
Ok! I'll give a try with 1.3 version and I'll let you know.
Em qui., 18 de nov. de 2021 16:05, Adam Pluciński @.***> escreveu:
...but 😄 it seems that in cake 1.3.0 it was fixed - can you please force upgrade to 1.3.0?
this is from my machine [image: image] https://user-images.githubusercontent.com/1914201/142480354-3eafbfb9-a49b-4cb3-a739-3f7cd186b511.png
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cake-build/cake/issues/3540#issuecomment-973170417, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAL64CIT7JKZ5FF2QB3OE63UMVFA3ANCNFSM5FRR4Z4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
@AdaskoTheBeAsT @rodrigoramos FYI I still see the same error with Cake 1.3.0:
#addin "nuget:?package=Microsoft.Data.SqlClient&version=3.0.0&loaddependencies=true"
var target = Argument("target", "Test");
Task("Test")
.Does(() =>
{
const string connStr = "Data Source=server;";
var conn = new Microsoft.Data.SqlClient.SqlConnection(connStr);
});
RunTarget(target);
That is really mysterious thing - i will try to uninstall vs mono etc and start with clean state
hi
@rodrigoramos @augustoproiete could you please check with .net core 6.0.101?
it seems it is not connected with cake
Is this still an issue I just in Cake 2.1 tried the following
#addin nuget:?package=Microsoft.Data.SqlClient&version=4.1.0&loaddependencies=true
var target = Argument("target", "Test");
Task("Test")
.Does(() =>
{
const string connStr = "Data Source=localhost,1433;Integrated Security=False;User ID=SA;Password=YourStrong@Passw0rd;Encrypt=False";
var conn = new Microsoft.Data.SqlClient.SqlConnection(connStr);
conn.Open();
});
RunTarget(target);
And it ran without error
This issue seems to have been fixed, if issue persists please feel free to reopen issue.
This issue seems to have been fixed, if issue persists please feel free to reopen issue.
Nope, happens again:
Resolving assembly 'Microsoft.Data.SqlClient.resources, Version=5.0.0.0, Culture=en-US, PublicKeyToken=23ec7fc2d6eaa4a5' using runtime installed at 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.3\'... Exception occurred while resolving assembly Microsoft.Data.SqlClient.resources: Could not load file or assembly 'Microsoft.Data.SqlClient.resources, Version=5.0.0.0, Culture=en-US, PublicKeyToken=23ec7fc2d6eaa4a5'. The system cannot find the file specified. Trying to resolve assembly Microsoft.Data.SqlClient.resources as 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=en-US, PublicKeyToken=23ec7fc2d6eaa4a5'... Assembly Microsoft.Data.SqlClient resolved as 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' (file location: 'C:\Projects......\tools\Addins\Microsoft.Data.SqlClient.5.1.0\runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dll')
@Sebazzz Do you have a Cake script that reproduces this error?
#addin nuget:?package=Microsoft.Data.SqlClient&version=5.1.0&loaddependencies=true
using Microsoft.Data.SqlClient;
var connectionString = $"Data Source=localhost;Application Name=Build Script;Initial Catalog=master;Integrated Security=true;Encrypt=false";
void ExecuteSqlCommand(string command) {
Verbose("Opening connection to {0}", connectionString);
using SqlConnection sqlConnection = new(connectionString);
sqlConnection.Open();
Verbose("Executing command: {0}", command);
using SqlCommand cmd = (SqlCommand) sqlConnection.CreateCommand();
cmd.CommandText = command;
cmd.ExecuteNonQuery();
}
ExecuteSqlCommand("SELECT 1");
Running under .NET SDK 7.0.100.
@Sebazzz What OS are you running this on?
I'm not able to reproduce (on my laptop at least):
Analyzing build script...
Processing build script...
Installing addins...
Compiling build script...
Opening connection to Data Source=localhost;Application Name=Build Script;Initial Catalog=master;Integrated Security=true;Encrypt=false
dotnet tool list
Package Id Version Commands Manifest
-------------------------------------------------------------------------------------------------------------
cake.tool 3.0.0 dotnet-cake /Users/augustoproiete/cake/tool/3.0.0/.config/dotnet-tools.json
dotnet --info
.NET SDK:
Version: 7.0.101
Commit: bb24aafa11
Runtime Environment:
OS Name: Mac OS X
OS Version: 13.2
OS Platform: Darwin
RID: osx.13-x64
Base Path: /usr/local/share/dotnet/sdk/7.0.101/
Host:
Version: 7.0.1
Architecture: x64
Commit: 97203d38ba
.NET SDKs installed:
3.1.202 [/usr/local/share/dotnet/sdk]
3.1.300 [/usr/local/share/dotnet/sdk]
3.1.301 [/usr/local/share/dotnet/sdk]
3.1.302 [/usr/local/share/dotnet/sdk]
3.1.402 [/usr/local/share/dotnet/sdk]
3.1.414 [/usr/local/share/dotnet/sdk]
5.0.100 [/usr/local/share/dotnet/sdk]
5.0.102 [/usr/local/share/dotnet/sdk]
5.0.203 [/usr/local/share/dotnet/sdk]
5.0.402 [/usr/local/share/dotnet/sdk]
6.0.100 [/usr/local/share/dotnet/sdk]
6.0.101 [/usr/local/share/dotnet/sdk]
6.0.301 [/usr/local/share/dotnet/sdk]
7.0.100 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
@augustoproiete I can't either anymore. I think Cake doesn't honor loaddependencies
if the main dependency is already locally restored - because after a clean build I was able to use it as expected.
@Sebazzz I tried building a few times both on OSX and Windows 11 and couldn't reproduce. If you find a way to repro this let us know
Prerequisites
Cake runner
Cake .NET Tool, Cake runner for .NET Core
Cake version
1.2.0
Operating system
Linux
Operating system architecture
64-Bit
CI Server
No response
What are you seeing?
It's not possible to use Microsoft.Data.SqlClient nuget on cake script. Some addins like Cake.SqlServer and Cake.SqlTools cannot be used.
The following error is showed:
What is expected?
I expect to be able to use this package. Like a I said before, it's referenced by addins which handles databases.
In the same machine/environment, we create a new console application, adding the same package as reference and running this application, it'll work as expected.
Steps to Reproduce
Create a build.cake script with the following contents:
Output log