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

Windows 10: System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform. #2534

Closed
colinangusmackay opened this issue Apr 24, 2019 · 6 comments
Assignees
Labels
Bug
Milestone

Comments

@colinangusmackay
Copy link

@colinangusmackay colinangusmackay commented Apr 24, 2019

What You Are Seeing?

I'm getting the error

Error: One or more errors occurred. (System.Data.SqlClient is not supported on this platform.)
        System.Data.SqlClient is not supported on this platform.

This is after following the advice in this other ticket: #2275 (comment)

What is Expected?

That the script runs and can use the SqlConnectionStringBuilder class which is located in that assembly.

What version of Cake are you using?

0.33

What environment are you running on? Windows? Linux? Mac?

Windows 10, 64-bit

Are you running on a CI Server? If so, which one?

No, but the script will eventually be extended to run on Team City and Jenkins.

How Did You Get This To Happen? (Steps to Reproduce)

See this gist:
https://gist.github.com/colinangusmackay/ddb0fe0b6c3f9d6f2958de8b8d8c4dfb

The command line used was:

.\build.ps1 -Script .\migrate-local.cake -Verbosity:Diagnostic

Output Log

PS C:\dev\cake-sqlclient-issue> .\build.ps1 -Script .\migrate-local.cake -Verbosity:Diagnostic
Bootstrapping .\migrate-local.cake with arguments:
.\migrate-local.cake -verbosity=Diagnostic --bootstrap
Module directory does not exist.
NuGet.config not found.
Analyzing C:/dev/cake-sqlclient-issue/migrate-local.cake...
Analyzing C:/dev/cake-sqlclient-issue/common-migrations.cake...

Running .\migrate-local.cake with arguments:
.\migrate-local.cake -verbosity=Diagnostic
Module directory does not exist.
NuGet.config not found.
Analyzing build script...
Analyzing C:/dev/cake-sqlclient-issue/migrate-local.cake...
Analyzing C:/dev/cake-sqlclient-issue/common-migrations.cake...
Processing build script...
Installing addins...
Found package 'System.Data.SqlClient 4.6.0' in 'C:/dev/cake-sqlclient-issue/tools/Addins'.
Package System.Data.SqlClient.4.6.0 has already been installed.
Successfully installed 'System.Data.SqlClient 4.6.0' to C:/dev/cake-sqlclient-issue/tools/Addins
Executing nuget actions took 56.22 ms
The addin System.Data.SqlClient will reference System.Data.SqlClient.dll.
Verifying assembly 'System.Data.SqlClient, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Adding assembly reference to System.Private.CoreLib.dll...
Adding assembly reference to System.Linq.Expressions.dll...
Adding assembly reference to Cake.Core.dll...
Adding assembly reference to Cake.Common.dll...
Adding assembly reference to netstandard.dll...
Adding assembly reference to Microsoft.Win32.Registry.dll...
Adding assembly reference to System.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.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.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.TFBuild...
Importing namespace Cake.Common.Build.TFBuild.Data...
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...
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.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.Export...
Importing namespace Cake.Common.Tools.GitReleaseManager.Label...
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.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.Data.SqlClient...
Importing namespace System.IO...
Importing namespace System.Linq...
Importing namespace System.Text...
Importing namespace System.Text.RegularExpressions...
Importing namespace System.Threading.Tasks...
Compiling build script...

========================================
Publish-Migrations
========================================
Executing task: Publish-Migrations
Finished executing task: Publish-Migrations

========================================
Run-Migrations
========================================
Executing task: Run-Migrations
Original Connection String: Server=my-server;Database=my-database;trusted_connection=true;application name=MigrationViaCakeScript;
An error occurred when executing task 'Run-Migrations'.
Error: System.AggregateException: One or more errors occurred. (System.Data.SqlClient is not supported on this platform.) ---> System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform.
   at System.Data.SqlClient.SqlConnectionStringBuilder..ctor(String connectionString)
   at Submission#0.GetLocalConnectionString(String originalConnectionString)
   at Submission#0.<<Initialize>>b__0_1()
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass24_0.<Does>b__0(ICakeContext x) 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 125
   at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context) in C:\projects\cake\src\Cake.Core\DefaultExecutionStrategy.cs:line 87
   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 336
   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 284
   at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 247
   at Cake.Scripting.BuildScriptHost.RunTargetAsync(String target) in C:\projects\cake\src\Cake\Scripting\BuildScriptHost.cs:line 47
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target) in C:\projects\cake\src\Cake.Core\Scripting\ScriptHost.cs:line 191
   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.Scripting.Roslyn.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Scripting\Roslyn\RoslynScriptSession.cs:line 136
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 212
   at Cake.Commands.BuildCommand.Execute(CakeOptions options) in C:\projects\cake\src\Cake\Commands\BuildCommand.cs:line 41
   at Cake.CakeApplication.Run(CakeOptions options) in C:\projects\cake\src\Cake\CakeApplication.cs:line 45
   at Cake.Program.Main() in C:\projects\cake\src\Cake\Program.cs:line 73
---> (Inner Exception #0) System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform.
   at System.Data.SqlClient.SqlConnectionStringBuilder..ctor(String connectionString)
   at Submission#0.GetLocalConnectionString(String originalConnectionString)
   at Submission#0.<<Initialize>>b__0_1()
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass24_0.<Does>b__0(ICakeContext x) 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 125
   at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context) in C:\projects\cake\src\Cake.Core\DefaultExecutionStrategy.cs:line 87
   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 336
   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 284
   at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 247
   at Cake.Scripting.BuildScriptHost.RunTargetAsync(String target) in C:\projects\cake\src\Cake\Scripting\BuildScriptHost.cs:line 47
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target) in C:\projects\cake\src\Cake.Core\Scripting\ScriptHost.cs:line 191
   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)<---

Variants

Remove System.Data.SqlClient altogether

If I remove the #addin line on common-migrations.cake then the error I get is:

error CS0234: The type or namespace name 'SqlClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
C:/dev/cake-sqlclient-issue/common-migrations.cake(8,23): error CS0246: The type or namespace name 'SqlConnectionStringBuilder' could not be found (are you missing a using directive or an assembly reference?)
Error: Cake.Core.CakeException: Error(s) occurred when compiling build script:
error CS0234: The type or namespace name 'SqlClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
C:/dev/cake-sqlclient-issue/common-migrations.cake(8,23): error CS0246: The type or namespace name 'SqlConnectionStringBuilder' could not be found (are you missing a using directive or an assembly reference?)
   at Cake.Scripting.Roslyn.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Scripting\Roslyn\RoslynScriptSession.cs:line 82
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 212
   at Cake.Commands.BuildCommand.Execute(CakeOptions options) in C:\projects\cake\src\Cake\Commands\BuildCommand.cs:line 41
   at Cake.CakeApplication.Run(CakeOptions options) in C:\projects\cake\src\Cake\CakeApplication.cs:line 45
   at Cake.Program.Main() in C:\projects\cake\src\Cake\Program.cs:line 73

Ignore advice in #2275

If I ignore the advice in issue #2275, and just have

#addin nuget:?package=System.Data.SqlClient&version=4.6.0

Then the error I get is:

Bootstrapping .\migrate-local.cake with arguments:
.\migrate-local.cake -verbosity=Diagnostic --bootstrap
Module directory does not exist.
NuGet.config not found.
Analyzing C:/dev/cake-sqlclient-issue/migrate-local.cake...
Analyzing C:/dev/cake-sqlclient-issue/common-migrations.cake...

Running .\migrate-local.cake with arguments:
.\migrate-local.cake -verbosity=Diagnostic
Module directory does not exist.
NuGet.config not found.
Analyzing build script...
Analyzing C:/dev/cake-sqlclient-issue/migrate-local.cake...
Analyzing C:/dev/cake-sqlclient-issue/common-migrations.cake...
Processing build script...
Installing addins...
Found package 'System.Data.SqlClient 4.6.0' in 'C:/dev/cake-sqlclient-issue/tools/Addins'.
Package System.Data.SqlClient.4.6.0 has already been installed.
Successfully installed 'System.Data.SqlClient 4.6.0' to C:/dev/cake-sqlclient-issue/tools/Addins
Executing nuget actions took 54.28 ms
The addin System.Data.SqlClient will reference System.Data.SqlClient.dll.
The addin System.Data.SqlClient will reference System.Data.SqlClient.dll.
The addin System.Data.SqlClient will reference System.Data.SqlClient.dll.
Verifying assembly 'System.Data.SqlClient, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Error: System.IO.FileLoadException: Assembly with same name is already loaded
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Cake.Core.Reflection.AssemblyLoader.Load(FilePath path, Boolean verify) in C:\projects\cake\src\Cake.Core\Reflection\AssemblyLoader.cs:line 31
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 171
   at Cake.Commands.BuildCommand.Execute(CakeOptions options) in C:\projects\cake\src\Cake\Commands\BuildCommand.cs:line 41
   at Cake.CakeApplication.Run(CakeOptions options) in C:\projects\cake\src\Cake\CakeApplication.cs:line 45
   at Cake.Program.Main() in C:\projects\cake\src\Cake\Program.cs:line 73

This is odd, because it is now referencing an older version of the assembly. (4.5 instead of the specified 4.6)

So, I thought what if I specify v4.5... Same error except it now trying to load v4.4

@colinangusmackay

This comment has been minimized.

Copy link
Author

@colinangusmackay colinangusmackay commented Apr 24, 2019

@mholo65 As per your chat request: April 22, 2019 3:14 PM

@senioroman4uk

This comment has been minimized.

Copy link

@senioroman4uk senioroman4uk commented Jun 16, 2019

Hi! I am facing the same issue, any updates on it?

@mholo65 mholo65 self-assigned this Jun 16, 2019
@mholo65 mholo65 added this to the v0.34.0 milestone Jun 16, 2019
@mholo65 mholo65 added the Bug label Jun 16, 2019
@mholo65

This comment has been minimized.

Copy link
Member

@mholo65 mholo65 commented Jun 16, 2019

No, no updates. Haven’t had any time to look at it yet. I’ve assigned to me so I’ll not forget about it.

@devlead devlead modified the milestones: v0.34.0, v0.35.0 Jul 16, 2019
@devlead devlead modified the milestones: v0.35.0, v0.36.0 Sep 28, 2019
@senioroman4uk

This comment has been minimized.

Copy link

@senioroman4uk senioroman4uk commented Oct 25, 2019

Guys do you need any help? I see this issue being moved from release to release, maybe I can start working on it?

@mholo65

This comment has been minimized.

Copy link
Member

@mholo65 mholo65 commented Oct 25, 2019

@senioroman4uk actually, I have a pending PR which fixes this, see #2564, haven't got around fixing it yet. My PR needs rebaseing and fixing some of the comments, otherwise it should be good to go!

@devlead

This comment has been minimized.

Copy link
Member

@devlead devlead commented Dec 9, 2019

Fixed by #2564

@devlead devlead closed this Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.