Skip to content

Missing libSystem.Net.Security.Native.so when publishing self-contained single-file project on Linux #88481

@julesroussel3

Description

@julesroussel3

Description

When publishing a .NET project as a self-contained single-file application on the Linux platform, the resulting binary does not include the required libSystem.Net.Security.Native.so library. This issue is observed specifically when using Microsoft.Data.SqlClient or System.Data.SqlClient libraries and calling the SqlConnection.Open() method with Integrated_Security=true in the connection string.

Reproduction Steps

  1. Write a program which uses the Microsoft.Data.SqlClient or System.Data.SqlClient libraries.

  2. Call the SqlConnection.Open() method with Integrated_Security=true in the connection string.

  3. Build the project: dotnet publish --framework net6.0 --runtime linux-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:IncludeAllContentForSelfExtract=true

  4. Execute the published binary.

  5. Encounter the following exception if:

    1. libSystem.Net.Security.Native.so is not present in the program's directory or library path, or:
    2. dotnet framework is not installed, which should not be necessary with self-contained applications.
    Microsoft.Data.SqlClient.SqlException (0x80131904): The type initializer for 'NetSecurityNative' threw an exception.
    

Code sample:

  • project.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <RootNamespace>dotnet_test</RootNamespace>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
  </ItemGroup>

</Project>
  • Program.cs
using System;
using Microsoft.Data.SqlClient; // or System.Data.SqlClient

class Program
{
    static void Main()
    {
        // Connection string with Integrated Security
        string connectionString = "Server=myServerAddress;Database=myDatabase;Integrated Security=true;Encrypt=false;";

        try
        {
            // Create a new SqlConnection using the connection string
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                // Open the connection
                connection.Open(); // Exception occurs here if libSystem.Net.Security.Native.so is missing
            }

            Console.WriteLine("Connection successful!");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Exception: {ex}");
        }
    }
}

Expected behavior

The published self-contained single-file binary should include the libSystem.Net.Security.Native.so library, ensuring the program's functionality without the need for manual copying of the library or the need for the dotnet framework to be installed on the local machine.

Actual behavior

Running the program results in the following exception:

Microsoft.Data.SqlClient.SqlException (0x80131904): The type initializer for 'NetSecurityNative' threw an exception.

Regression?

No response

Known Workarounds

The known workaround, which is unacceptable for self-contained single-file programs, is to ensure libSystem.Net.Security.Native.so is in the library path of the running program.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions