Skip to content

Microsoft.Data.SqlClient is not supported on this platform with .NET9 class library and winforms app #3006

Closed

Description

@heckradr

Microsoft.Data.SqlClient is not supported on this platform

On a windows 11 pc with the latest Visual Studio 2022 (17.13.0, preview 1) I get an exception "Microsoft.Data.SqlClient is not supported on this platform" when using EF Core in an DLL project which is referenced by another project (for example a winforms project).

I'm using EF-Core 9 with .NET 9 (but encountered the same problem with .NET8).

I saw other issues with this exception in combination with .NET Standard (#2840) or .NET Framework (#2786), but in my case there are only .NET8/9 projects involved.

You can solve the problem by including the Microsoft.Data.SqlClient NuGet package directly in the WinForms project. However, I see this as just a workaround; it should actually work without this direct reference.

Exception message:
Microsoft.Data.SqlClient is not supported on this platform

Reproduce / test repo

I created a test repo to show this problem: https://github.com/heckradr/SQL-Client-Problems

Further technical details

Microsoft.Data.SqlClient version: 5.16.24240.5 (but same problem with 5.22.24240.6)
.NET target: .NET9
SQL Server version: SQL Server 2022
Operating system: Windows 11 23H2 (22631.4460)

Activity

  1. added
    Repro Available ✔️
    and removed on Nov 15, 2024
  2. cheenamalhotra commented on Mar 25, 2025

    @cheenamalhotra
    Member

    @heckradr

    Have you tried including in your TestOutsideSolution project file:

    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
    
  3. added and removed
    Repro Available ✔️
    on Mar 25, 2025
  4. heckradr commented on Mar 25, 2025

    @heckradr
    Author

    @cheenamalhotra

    I added RuntimeIdentifiers to my test repository and committed the changes. However, I am still encountering the same error.

  5. heckradr commented on Jul 20, 2025

    @heckradr
    Author

    @cheenamalhotra did you have a chance to look into this issue? I'm still encountering the same error, even with the latest versions. Thanks in advance!

  6. ErikEJ commented on Jul 20, 2025

    @ErikEJ
    Contributor

    Why would you actually expect the single .dll reference to work??

  7. heckradr commented on Jul 20, 2025

    @heckradr
    Author

    Why would you actually expect the single .dll reference to work??

    Counter question: Why shouldn't it work? All the necessary DLLs are in the output directory, but the SQL client seems to have trouble recognizing which platform it's running on.

    I don't want to integrate every transitive dependency into my application as a direct dependency.

  8. bauradar commented on Aug 16, 2025

    @bauradar

    If you copy C:\Users<myUser>.nuget\packages\microsoft.data.sqlclient\6.1.1\runtimes\win\lib\net9.0\Microsoft.Data.SqlClient.dll
    manually to your output directory after compile it works as expected.

    The files have the same name, but differ allready in size: working: 2.117KB vs. not working 909KB

    Nevertheless this is very annoying.

  9. heckradr commented on Aug 24, 2025

    @heckradr
    Author

    If you copy C:\Users.nuget\packages\microsoft.data.sqlclient\6.1.1\runtimes\win\lib\net9.0\Microsoft.Data.SqlClient.dll manually to your output directory after compile it works as expected.

    The files have the same name, but differ allready in size: working: 2.117KB vs. not working 909KB

    Nevertheless this is very annoying.

    In my test scenario, the file is 270 KB in both the running version and the faulty app. It's always the same file (MD5 checked). Therefore, it can't be related to the DLL itself.

  10. bauradar commented on Aug 25, 2025

    @bauradar

    Hi,

    add also Microsoft.Data.SqlClient.SNI.dll to your outuput.

    Niko

  11. moved this from To triage to Backlog in SqlClient Boardon Oct 27, 2025
  12. moved this from Backlog to In progress in SqlClient Boardon Sep 10, 2026
  13. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  14. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Bug
    Environment All required environment details provided for investigation
    Area Area\Engineering
    Duplicates Potentially related: #2840, #2786 (referenced by reporter); a fix PR is already linked to this issue: #4673 "Remove RID-specific SqlClient DLLs"
    Regression Not indicated (issue is about RID-specific asset resolution, not a version regression)

    Analysis

    This is a packaging/build issue: when Microsoft.Data.SqlClient is referenced only transitively (via a class library that is itself referenced by a WinForms/EXE project), MSBuild's asset-selection logic does not correctly copy the platform-specific (RID-specific) Microsoft.Data.SqlClient.dll/Microsoft.Data.SqlClient.SNI.dll to the final executable's output directory, causing the "is not supported on this platform" PlatformNotSupportedException at runtime. Workarounds (adding an explicit direct package reference, setting RuntimeIdentifiers, or manually copying the correct DLL) confirm the root cause is asset selection/copy behavior rather than a logic bug in SqlClient itself. Severity: P2 (workaround exists, but affects any multi-project .NET 8/9 solution using transitive references, which is common). This issue already has an associated fix PR (#4673) that removes RID-specific SqlClient DLLs, which appears to directly address this class of problem.

    Next Steps

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #3006 · copilot · auto · 34 AIC · ⌖ 13.4 AIC · ⊞ 11.9K · ◷

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

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions