question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It's not possible to use Microsoft.Data.SqlClient

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

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:

An error occurred when executing task 'Test'.
Error: One or more errors occurred. (Strings.PlatformNotSupported_DataSqlClient)
	Strings.PlatformNotSupported_DataSqlClient

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

  1. In a new folder, create dotnet tool manifest:
    dotnet new tool-manifest
    
  2. Install cake tool
    dotnet tool install Cake.Tool --version 1.2.0
    
  3. Create a build.cake script with the following contents:
    #addin "nuget:?package=Microsoft.Data.SqlClient&version=3.0.0"
    
    var target = Argument("target", "Test");
    
    Task("Test")
      .Does(() =>
      {
          const string connStr = "<your connection string>";
    
          var conn = new Microsoft.Data.SqlClient.SqlConnection(connStr);
    
      });
    
     RunTarget(target);
    
  4. Run cake script:
    dotnet cake
    

Output log

Looking for modules...
No modules found to install.
Module directory does not exist.
Analyzing build script...
Analyzing /tmp/fk/build.cake...
Processing build script...
Installing addins...
Resolving assembly 'System.Private.Uri.resources, Version=4.0.6.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a' using runtime installed at '/home/rramos/.dotnet/shared/Microsoft.NETCore.App/3.1.18/'...
Exception occurred while resolving assembly System.Private.Uri.resources: Could not load file or assembly 'System.Private.Uri.resources, Version=4.0.6.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Trying to resolve assembly System.Private.Uri.resources as 'System.Private.Uri, Version=4.0.6.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'...
Assembly System.Private.Uri resolved as 'System.Private.Uri, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' (file location: '/home/rramos/.dotnet/shared/Microsoft.NETCore.App/3.1.18/System.Private.Uri.dll')
The addin Microsoft.Data.SqlClient will reference Microsoft.Data.SqlClient.dll.
Verifying assembly 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'.
Adding assembly reference to System.Private.CoreLib.dll...
Adding assembly reference to System.Linq.Expressions.dll...
Adding assembly reference to Microsoft.CSharp.dll...
Adding assembly reference to Cake.Core.dll...
Adding assembly reference to Cake.Common.dll...
Adding assembly reference to Spectre.Console.dll...
Adding assembly reference to netstandard.dll...
Adding assembly reference to Microsoft.Win32.Registry.dll...
Adding assembly reference to System.Memory.dll...
Adding assembly reference to Wcwidth.dll...
Adding assembly reference to Microsoft.Data.SqlClient.dll...
Importing namespace Cake.Common...
Importing namespace Cake.Common.Build...
Importing namespace Cake.Common.Build.AppVeyor...
Importing namespace Cake.Common.Build.AppVeyor.Data...
Importing namespace Cake.Common.Build.AzurePipelines...
Importing namespace Cake.Common.Build.AzurePipelines.Data...
Importing namespace Cake.Common.Build.Bamboo...
Importing namespace Cake.Common.Build.Bamboo.Data...
Importing namespace Cake.Common.Build.BitbucketPipelines...
Importing namespace Cake.Common.Build.BitbucketPipelines.Data...
Importing namespace Cake.Common.Build.Bitrise...
Importing namespace Cake.Common.Build.Bitrise.Data...
Importing namespace Cake.Common.Build.ContinuaCI...
Importing namespace Cake.Common.Build.ContinuaCI.Data...
Importing namespace Cake.Common.Build.GitHubActions...
Importing namespace Cake.Common.Build.GitHubActions.Data...
Importing namespace Cake.Common.Build.GitLabCI...
Importing namespace Cake.Common.Build.GitLabCI.Data...
Importing namespace Cake.Common.Build.GoCD...
Importing namespace Cake.Common.Build.GoCD.Data...
Importing namespace Cake.Common.Build.Jenkins...
Importing namespace Cake.Common.Build.Jenkins.Data...
Importing namespace Cake.Common.Build.MyGet...
Importing namespace Cake.Common.Build.TeamCity...
Importing namespace Cake.Common.Build.TravisCI...
Importing namespace Cake.Common.Build.TravisCI.Data...
Importing namespace Cake.Common.Diagnostics...
Importing namespace Cake.Common.IO...
Importing namespace Cake.Common.IO.Paths...
Importing namespace Cake.Common.Net...
Importing namespace Cake.Common.Security...
Importing namespace Cake.Common.Solution...
Importing namespace Cake.Common.Solution.Project...
Importing namespace Cake.Common.Solution.Project.Properties...
Importing namespace Cake.Common.Solution.Project.XmlDoc...
Importing namespace Cake.Common.Text...
Importing namespace Cake.Common.Tools.Cake...
Importing namespace Cake.Common.Tools.Chocolatey...
Importing namespace Cake.Common.Tools.Chocolatey.ApiKey...
Importing namespace Cake.Common.Tools.Chocolatey.Config...
Importing namespace Cake.Common.Tools.Chocolatey.Download...
Importing namespace Cake.Common.Tools.Chocolatey.Features...
Importing namespace Cake.Common.Tools.Chocolatey.Install...
Importing namespace Cake.Common.Tools.Chocolatey.New...
Importing namespace Cake.Common.Tools.Chocolatey.Pack...
Importing namespace Cake.Common.Tools.Chocolatey.Pin...
Importing namespace Cake.Common.Tools.Chocolatey.Push...
Importing namespace Cake.Common.Tools.Chocolatey.Sources...
Importing namespace Cake.Common.Tools.Chocolatey.Uninstall...
Importing namespace Cake.Common.Tools.Chocolatey.Upgrade...
Importing namespace Cake.Common.Tools.DotCover...
Importing namespace Cake.Common.Tools.DotCover.Analyse...
Importing namespace Cake.Common.Tools.DotCover.Cover...
Importing namespace Cake.Common.Tools.DotCover.Merge...
Importing namespace Cake.Common.Tools.DotCover.Report...
Importing namespace Cake.Common.Tools.DotNetCore...
Importing namespace Cake.Common.Tools.DotNetCore.Build...
Importing namespace Cake.Common.Tools.DotNetCore.BuildServer...
Importing namespace Cake.Common.Tools.DotNetCore.Clean...
Importing namespace Cake.Common.Tools.DotNetCore.Execute...
Importing namespace Cake.Common.Tools.DotNetCore.MSBuild...
Importing namespace Cake.Common.Tools.DotNetCore.NuGet.Delete...
Importing namespace Cake.Common.Tools.DotNetCore.NuGet.Push...
Importing namespace Cake.Common.Tools.DotNetCore.NuGet.Source...
Importing namespace Cake.Common.Tools.DotNetCore.Pack...
Importing namespace Cake.Common.Tools.DotNetCore.Publish...
Importing namespace Cake.Common.Tools.DotNetCore.Restore...
Importing namespace Cake.Common.Tools.DotNetCore.Run...
Importing namespace Cake.Common.Tools.DotNetCore.Test...
Importing namespace Cake.Common.Tools.DotNetCore.Tool...
Importing namespace Cake.Common.Tools.DotNetCore.VSTest...
Importing namespace Cake.Common.Tools.DupFinder...
Importing namespace Cake.Common.Tools.Fixie...
Importing namespace Cake.Common.Tools.GitLink...
Importing namespace Cake.Common.Tools.GitReleaseManager...
Importing namespace Cake.Common.Tools.GitReleaseManager.AddAssets...
Importing namespace Cake.Common.Tools.GitReleaseManager.Close...
Importing namespace Cake.Common.Tools.GitReleaseManager.Create...
Importing namespace Cake.Common.Tools.GitReleaseManager.Discard...
Importing namespace Cake.Common.Tools.GitReleaseManager.Export...
Importing namespace Cake.Common.Tools.GitReleaseManager.Label...
Importing namespace Cake.Common.Tools.GitReleaseManager.Open...
Importing namespace Cake.Common.Tools.GitReleaseManager.Publish...
Importing namespace Cake.Common.Tools.GitReleaseNotes...
Importing namespace Cake.Common.Tools.GitVersion...
Importing namespace Cake.Common.Tools.ILMerge...
Importing namespace Cake.Common.Tools.ILRepack...
Importing namespace Cake.Common.Tools.InnoSetup...
Importing namespace Cake.Common.Tools.InspectCode...
Importing namespace Cake.Common.Tools.MSBuild...
Importing namespace Cake.Common.Tools.MSpec...
Importing namespace Cake.Common.Tools.MSTest...
Importing namespace Cake.Common.Tools.NSIS...
Importing namespace Cake.Common.Tools.NuGet...
Importing namespace Cake.Common.Tools.NuGet.Add...
Importing namespace Cake.Common.Tools.NuGet.Delete...
Importing namespace Cake.Common.Tools.NuGet.Init...
Importing namespace Cake.Common.Tools.NuGet.Install...
Importing namespace Cake.Common.Tools.NuGet.List...
Importing namespace Cake.Common.Tools.NuGet.Pack...
Importing namespace Cake.Common.Tools.NuGet.Push...
Importing namespace Cake.Common.Tools.NuGet.Restore...
Importing namespace Cake.Common.Tools.NuGet.SetApiKey...
Importing namespace Cake.Common.Tools.NuGet.SetProxy...
Importing namespace Cake.Common.Tools.NuGet.Sources...
Importing namespace Cake.Common.Tools.NuGet.Update...
Importing namespace Cake.Common.Tools.NUnit...
Importing namespace Cake.Common.Tools.OctopusDeploy...
Importing namespace Cake.Common.Tools.OpenCover...
Importing namespace Cake.Common.Tools.ReportGenerator...
Importing namespace Cake.Common.Tools.ReportUnit...
Importing namespace Cake.Common.Tools.Roundhouse...
Importing namespace Cake.Common.Tools.SignTool...
Importing namespace Cake.Common.Tools.SpecFlow...
Importing namespace Cake.Common.Tools.SpecFlow.StepDefinitionReport...
Importing namespace Cake.Common.Tools.SpecFlow.TestExecutionReport...
Importing namespace Cake.Common.Tools.TextTransform...
Importing namespace Cake.Common.Tools.VSTest...
Importing namespace Cake.Common.Tools.VSWhere...
Importing namespace Cake.Common.Tools.VSWhere.All...
Importing namespace Cake.Common.Tools.VSWhere.Latest...
Importing namespace Cake.Common.Tools.VSWhere.Legacy...
Importing namespace Cake.Common.Tools.VSWhere.Product...
Importing namespace Cake.Common.Tools.WiX...
Importing namespace Cake.Common.Tools.WiX.Heat...
Importing namespace Cake.Common.Tools.XBuild...
Importing namespace Cake.Common.Tools.XUnit...
Importing namespace Cake.Common.Xml...
Importing namespace Cake.Core...
Importing namespace Cake.Core.Diagnostics...
Importing namespace Cake.Core.IO...
Importing namespace Cake.Core.Scripting...
Importing namespace System...
Importing namespace System.Collections.Generic...
Importing namespace System.IO...
Importing namespace System.Linq...
Importing namespace System.Text...
Importing namespace System.Threading.Tasks...
Compiling build script...

========================================
Test
========================================
Executing task: Test
An error occurred when executing task 'Test'.
Error: System.AggregateException: One or more errors occurred. (Strings.PlatformNotSupported_DataSqlClient)
 ---> System.PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient
   at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in /_/artifacts/Project/obj/Release.AnyCPU/Microsoft.Data.SqlClient/netcore/netcoreapp3.1/Microsoft.Data.SqlClient.notsupported.cs:line 386
   at Submission#0.<>c.<<Initialize>>b__0_0()
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass31_0.<Does>b__0(ICakeContext _) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 26
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass34_0.<Does>b__0(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 82
   at Cake.Core.CakeTask.Execute(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTask.cs:line 119
   at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context) in C:\projects\cake\src\Cake.Core\DefaultExecutionStrategy.cs:line 74
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 278
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 303
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 311
   at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 226
   at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 189
   at Cake.Cli.BuildScriptHost`1.RunTargetAsync(String target) in C:\projects\cake\src\Cake.Cli\Hosts\BuildScriptHost.cs:line 73
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target) in C:\projects\cake\src\Cake.Core\Scripting\ScriptHost.cs:line 105
   at Submission#0.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Cake.Infrastructure.Scripting.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Infrastructure\Scripting\RoslynScriptSession.cs:line 167
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 173
   at Cake.Features.Building.BuildFeature.RunCore(IRemainingArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 99
   at Cake.Features.Building.BuildFeature.Run(IRemainingArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 49
   at Cake.Commands.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings) in C:\projects\cake\src\Cake\Commands\DefaultCommand.cs:line 72

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:20 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
Sebazzzcommented, Mar 2, 2023
#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.

1reaction
AdaskoTheBeAsTcommented, Nov 15, 2021

Hi,

I will take a look at this and get back to you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Replacing System.Data.SqlClient with Microsoft. ...
Now, there is a request to replace the System.Data.SqlClient with Microsoft.Data.SqlClient due to end of support for that library.
Read more >
Could not load file or assembly System.Data.SqlClient
1. Make sure that the 'System.Data. · 2. Check if you have any configuration files in your project (e.g., 'app.config' or 'web. ·...
Read more >
SqlClient troubleshooting guide - ADO.NET Provider for ...
Recommended Solution: Ensure client application references minimum v2.1.0 version of Microsoft.Data.SqlClient package. When using EF Core, add a ...
Read more >
Microsoft.Data.SqlClient is not supported on this platform
Microsoft.Data.SqlClient is not supported on this platform. When using the portal to create Azure function in C#, System.Data.
Read more >
When Microsoft will release Entity Framework 6.x (.NET ...
Microsoft.Data.SQLClient is currently not supported in ef 6.x. I find Microsoft has stated some notes in their Github Status and Support:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found