Skip to content

Microsoft.Data.SqlClient is not supported on this platform #149

Open

Description

I've searched this repository along with the sqlclient repository. There are multiple issues bring this up but are either closed or solutions provided don't seem to fix the issue I'm getting.

I'm trying to create a basic binary module in PowerShell against SQL Server. I have a basic project structure with just one cmdlet so far (trying to see if this even works) that references SMO library.

Project: https://github.com/wsmelton/dbalight/tree/modulebuilder/source/dbalight

The project compiles for dotnet 6 on my M1 and the module imports with no issues. It is not until I call the Connect-DblServer:

Exception             : 
    Type       : System.PlatformNotSupportedException
    TargetSite : Void .ctor()
    Message    : Microsoft.Data.SqlClient is not supported on this platform.
    Source     : Microsoft.Data.SqlClient
    HResult    : -2146233031
    StackTrace : 
   at Microsoft.Data.SqlClient.SqlConnection..ctor()
   at Microsoft.SqlServer.Management.Common.ConnectionManager..ctor(IRenewableToken token, Boolean removeIntegratedSecurity)
   at Microsoft.SqlServer.Management.Common.ConnectionManager..ctor()
   at Microsoft.SqlServer.Management.Common.ServerConnection..ctor()
   at dbalight.cmdlets.general.ConnectServerCmdlet.ProcessRecord() in 
/Users/smelton/git/dbalight/source/dbalight/cmdlets/public/ConnectServer.cs:line 41
   at System.Management.Automation.Cmdlet.DoProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [Connect-DblServer], PlatformNotSupportedException
FullyQualifiedErrorId : System.PlatformNotSupportedException,dbalight.cmdlets.general.ConnectServerCmdlet
InvocationInfo        : 
    MyCommand        : Connect-DblDblServer
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 26
    Line             : Connect-DblServer -ServerInstance 'localhost,1432' -Verbose
    PositionMessage  : At line:1 char:1
                       + Connect-DblServer -ServerInstance 'localhost,1432' -Verbose
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Connect-DblServer
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Line 41 of that cs file for the cmdlet is: ServerConnection srvCn = new ServerConnection();

  • Is there something in my csproj that I have configured wrong?
  • Is this just broken and I need to revert to an older version of the SQLManagementObjects library?

Activity

  1. shueybubbles commented on Oct 10, 2023

    @shueybubbles
    Contributor

    is your deployment somehow copying the Microsoft.Data.SqlClient.dll file from lib instead of from runtimes ?

  2. DavoudEshtehari commented on Oct 11, 2023

    @DavoudEshtehari

    I tried to compile and use the sample project on ARM supported machine and I got the platform not supported exception on PS7. Then I tried locally on Windows 11 and x64, which didn't change the result. Can you share the commands and instructions if you could run it on a x64 supported machine and it's only an ARM related issue?
    image

  3. wsmelton commented on Oct 11, 2023

    @wsmelton
    Author
    Install-Module ModuleBuilder # or Install-PSResource ModuleBuilder
    ./build.ps1 -Verbose

    DavoudEshtehari run the above in PowerShell 7.2+ should get it going.

    I don't have access to any Windows device, only on a Apple Mac M1:

    image

    David Shiflet (@shueybubbles) on the build process I'm only running dotnet build -c Release so it creates in bin/net6.0/osx.12-arm64. The module build I'm copying that path up to the module's directory (minus the osx folder reference).

  4. DavoudEshtehari commented on Oct 11, 2023

    @DavoudEshtehari

    Seems it requires some more configurations! I followed the above instruction on the ARM machine.

    C:\Program Files\dotnet\sdk\7.0.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.GenerateAssemblyInfo.targets(209,5): e
    rror MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion". [C:\Users\
    dotnet\dbalight\source\dbalight\dbalight.csproj]
    
    Build FAILED.
    
    C:\Program Files\dotnet\sdk\7.0.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.GenerateAssemblyInfo.targets(209,5): e
    rror MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion". [C:\Users\
    dotnet\dbalight\source\dbalight\dbalight.csproj]
        0 Warning(s)
        1 Error(s)
    
    Time Elapsed 00:00:01.69
    WARNING: Module-Builder could not run, unable to find DLL library: dbalight.dll
    
  5. wsmelton commented on Oct 11, 2023

    @wsmelton
    Author

    I don't have Windows nor do I use it so unsure what additional requirements there would be to get the build of the project to run successful.

  6. wsmelton commented on Oct 14, 2023

    @wsmelton
    Author

    DavoudEshtehari that error comes from two things:

    1. You don't have the dotnet-gitversion installed on your machine
    2. You downloaded the zip of the project and didn't clone it. Cloning is required for gitversion to be used (it requires the git database for the project to be on your local device)
  7. wsmelton commented on Oct 15, 2023

    @wsmelton
    Author

    If I use either SMO for netstandard2.0 or net6.0 neither one seems to work on Mac.

    I have 6 and 7 SDK installed on the device:

    image
  8. DavoudEshtehari commented on Oct 16, 2023

    @DavoudEshtehari

    Shawn Melton (@wsmelton) Thanks, dotnet-gitversion was required and I confirm the build ran successfully either on x64 or ARM64 Win 11 machines, but the result is identical after running the following commands:

    Import-Module ...Output\dbalight\0.1.0\dbalight.dll
    Connect-Server

    Connect-Server: Microsoft.Data.SqlClient is not supported on this platform.

  9. shueybubbles commented on Mar 8, 2024

    @shueybubbles
    Contributor

    DavoudEshtehari should this issue move over to dotnet/sqlclient?

  10. DavoudEshtehari commented on Mar 8, 2024

    @DavoudEshtehari

    I don't have permission to move it into SqlClient. I'd appreciate it if you could do it.

  11. shueybubbles commented on Mar 8, 2024

    @shueybubbles
    Contributor

    you'd have to open a new one then we can close this one with a link to it. Moving issues only works within the same organization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions