Skip to content

dotnet publish -r linux-x64 resolves reference assembly instead of runtime assembly for net10.0 apps #4461

Closed as not planned

Description

@mahdiyar021

Describe the bug

When publishing a .NET 10 application with -r linux-x64 that references Microsoft.Data.SqlClient (transitively via Microsoft.EntityFrameworkCore.SqlServer), the publish output places the reference assembly from lib/net9.0/ at the output root instead of the Unix runtime assembly from runtimes/unix/lib/net9.0/. At runtime, the reference assembly throws PlatformNotSupportedException.

To Reproduce

  1. Create a .NET 10 app with a transitive dependency on Microsoft.Data.SqlClient 7.0.1 (e.g. via Microsoft.EntityFrameworkCore.SqlServer)
  2. Publish with RID:
    dotnet publish -c Release -r linux-x64 -o ./publish
  3. Run on Linux (Ubuntu 24.04, amd64):
    dotnet ./publish/App.dll
  4. Any attempt to create a SqlConnection throws:
    System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.

Expected behavior

The Unix runtime assembly (runtimes/unix/lib/net9.0/Microsoft.Data.SqlClient.dll, ~1.8 MB) should be placed at the publish root, not the reference assembly (lib/net9.0/Microsoft.Data.SqlClient.dll, ~632 KB).

Evidence

  • dotnet run (no publish, no RID) works correctly — the runtime resolves the Unix DLL dynamically
  • The .deps.json correctly references runtimes/unix/lib/net9.0/Microsoft.Data.SqlClient.dll
  • Both DLLs are present in the publish output, but the root one (632K) gets loaded instead of the unix one (1.8M)
  • The package only has net9.0 TFMs; the app targets net10.0 (TFM fallback gap may contribute)

Environment

  • Microsoft.Data.SqlClient: 7.0.1
  • .NET SDK: 10.0.302 (container: mcr.microsoft.com/dotnet/sdk:10.0)
  • .NET Runtime: 10.0.10
  • OS: Ubuntu 24.04.4 LTS, linux-x64
  • Publish command: dotnet publish -c Release -r linux-x64 -o ./publish

Workaround

An MSBuild target that copies the Unix runtime DLL over the reference assembly after publish:

<Target Name="FixSqlClientRuntimeAssembly" AfterTargets="Publish"
     Condition="$([System.String]::new('$(RuntimeIdentifier)').StartsWith('linux'))">
  <PropertyGroup>
 <SqlClientUnixRuntime>$(PublishDir)runtimes/unix/lib/net9.0/Microsoft.Data.SqlClient.dll</SqlClientUnixRuntime>
 <SqlClientRoot>$(PublishDir)Microsoft.Data.SqlClient.dll</SqlClientRoot>
  </PropertyGroup>
  <Copy SourceFiles="$(SqlClientUnixRuntime)" DestinationFiles="$(SqlClientRoot)"
     Condition="Exists('$(SqlClientUnixRuntime)')" />
</Target>

Related

Activity

  1. mahdiyar021 commented on Jul 20, 2026

    @mahdiyar021
    Author

    i fix this with this config :

      <!-- Fix Microsoft.Data.SqlClient runtime assembly resolution when publishing with -r linux-x64 -->
      <Target Name="FixSqlClientRuntimeAssembly" AfterTargets="Publish" Condition="$([System.String]::new('$(RuntimeIdentifier)').StartsWith('linux'))">
        <PropertyGroup>
          <SqlClientUnixRuntime>$(PublishDir)runtimes/unix/lib/net9.0/Microsoft.Data.SqlClient.dll</SqlClientUnixRuntime>
          <SqlClientRoot>$(PublishDir)Microsoft.Data.SqlClient.dll</SqlClientRoot>
        </PropertyGroup>
        <Message Importance="high" Text="Fixing Microsoft.Data.SqlClient runtime assembly for Linux..." />
        <Copy SourceFiles="$(SqlClientUnixRuntime)" DestinationFiles="$(SqlClientRoot)" Condition="Exists('$(SqlClientUnixRuntime)')" />
        <Message Importance="high" Text="Microsoft.Data.SqlClient runtime assembly replaced." Condition="Exists('$(SqlClientUnixRuntime)')" />
      </Target>
    
  2. github-actions commented on Jul 20, 2026

    @github-actions

    🔍 Triage Summary

    Check Result
    Issue type Bug
    Environment All required environment details provided for investigation
    Area Area\Netcore
    Duplicates Potentially related: #445, #2030, #1643, #1423
    Regression Likely regression — this previously worked in earlier .NET SDK versions and is now broken specifically with .NET 10 SDK + SqlClient 7.0.1

    Analysis

    When publishing a .NET 10 app with a RID (-r linux-x64) that takes a TFM fallback from net10.0 → net9.0, the .NET SDK's publish asset resolution picks up the lib/net9.0/ reference assembly (a stub that throws PlatformNotSupportedException) instead of runtimes/unix/lib/net9.0/ runtime assembly. This is a NuGet/SDK publish asset selection bug at the intersection of RID-specific asset resolution and TFM fallback — the .deps.json is correctly generated, but the wrong DLL wins the root output slot. The affected component is the NuGet package layout and/or MSBuild publish targets in the SqlClient package. Severity: P1 — blocks all Linux/macOS publish scenarios for .NET 10 apps consuming SqlClient 7.x.

    Next Steps

    • Assign to Copilot coding agent to investigate the NuGet package layout (runtimes/ vs lib/ asset precedence) and the MSBuild .targets / .props files shipped in the SqlClient package. Specifically, investigate whether the package needs a <RuntimeList> or explicit <PackagePath> overrides so the SDK prefers the runtime-specific assembly during RID-targeted publish. Review how runtimes/unix/lib/net9.0/ and lib/net9.0/ are declared in Microsoft.Data.SqlClient.nuspec and verify whether the .targets file should inject a CopyLocalLockFileAssemblies-style hint or an explicit asset copy step.
    • Verify whether adding a net10.0-targeted TFM to the package (rather than relying on net9.0 fallback) would fully resolve the issue, or whether the asset selection bug exists independently.
    • Cross-reference the resolution from Regression with published application: PlatformNotSupportedException #445 to understand why it regressed.
    • Consider shipping a patched 7.0.2 with the fix given the severity.

    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 issue #4461 · 31.2 AIC · ⌖ 6.48 AIC · ⊞ 8.4K · ◷

  3. cheenamalhotra commented on Jul 21, 2026

    @cheenamalhotra
    Member

    HI @mahdiyar021

    #445 (Regression with published application: PlatformNotSupportedException) — closed, but still reproducing on .NET 10 / SqlClient 7.0.1

    There was no past regression, please read the linked issue for more details. The behavior is govered by Dotnet SDK as also mentioned in the other issue. Removing -r linux-x64 should solve the issue.

  4. self-assigned this
    on Jul 21, 2026
  5. moved this from To triage to Waiting for customer in SqlClient Boardon Jul 21, 2026
  6. mahdiyar021 commented on Jul 21, 2026

    @mahdiyar021
    Author

    i know removing -r linux-x64 will solve the issue , but dont wanna publish this way

  7. cheenamalhotra commented on Aug 13, 2026

    @cheenamalhotra
    Member

    @mahdiyar021 please open issue for dotnet/runtime repo - as we don't control runtime identifiers and binary resolutions. This is Dotnet SDK issue.

    The recommended solutions should work and should be used until then.

  8. moved this from Waiting for customer to Done in SqlClient Boardon Aug 13, 2026
  9. added
    External 🔗
    on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

External 🔗

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions