Skip to content

NpgsqlConnectionStringBuilder.Remove and Clear leave Encoding and Kerberos Service Name in the connection string #6724

Description

@johnkaram02

Steps to reproduce

var builder = new NpgsqlConnectionStringBuilder("Host=myhost;Encoding=LATIN1;Kerberos Service Name=foo");
builder.Remove("Encoding");
builder.Remove("Kerberos Service Name");
Console.WriteLine(builder.ConnectionString);

builder = new NpgsqlConnectionStringBuilder("Host=myhost;Encoding=LATIN1");
builder.Clear();
Console.WriteLine($"{builder.Count} '{builder.ConnectionString}'");

The issue

Remove doesn't remove these two keys. It replaces them with their default values, so the first line prints Host=myhost;Encoding=UTF8;Kerberos Service Name=postgres instead of Host=myhost. Clear() leaves one key, so the second line prints 1 'Encoding=UTF8' instead of 0 ''. Setting builder["Encoding"] = null behaves the same way.

Other properties, such as SSL Mode and Command Timeout, are removed as expected. The difference is that Encoding and Kerberos Service Name are string properties with a non-null default value.

Further technical details

Npgsql version: main at b35800b
PostgreSQL version: not relevant (no connection is opened)
Operating system: Linux x86_64

Other details about my project setup: .NET SDK 10.0.403

Activity

  1. vonzshik commented on Nov 17, 2026

    @vonzshik
    Contributor

    Yep, seems to have broke when we were improving AOT size (around .NET 8 I think?).

    @lqkhanh295 could you please post anything here so I can assign this issue to you?

  2. added theissue type on Nov 17, 2026
  3. added this to the 10.0.4 milestone on Nov 17, 2026
  4. lqkhanh295 commented on Nov 17, 2026

    @lqkhanh295

    Hi @vonzshik, thanks for reviewing! Commenting here as requested so you can assign the issue.

  5. modified the milestones: 10.0.4, 10.0.5 on Nov 20, 2026
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

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions