Skip to content

The NpgsqlParameterCollection docs inherit misleading Add(object) docs #6150

Closed

Description

@adamyakes

The docs for NpgsqlParameterCollection.Add(object value) inherit a misleading statement for the value argument:

The Value of the DbParameter to add to the collection.

However, you're not adding the Value of the DbParameter, you should be adding a NpgsqlParameter

var cmd = new NpgsqlCommand("select * from foo where id = $1");

// works
cmd.Parameters.Add(new NpgsqlParameter() { Value = 1 });

// throws System.InvalidCastException: The value "1" is not of type "NpgsqlParameter" and cannot be used in this parameter collection.
cmd.Parameters.Add(1); 

I understand there are more idiomatic ways of doing things, but since ADO.NET tends to allow many ways of doing something, I'd propose that the docs call out that it must be an instance of NpgsqlParameter.

Activity

  1. NinoFloris commented on Jul 28, 2025

    @NinoFloris
    Member

    It's not exactly misleading, DbParameter is an abstract class after all. I do agree it's not as detailed as it ideally should be. I will mark it as an enhancement for whenever we'll get to it, PRs are also welcome.

  2. added this to the Backlog milestone on Jul 28, 2025
  3. added theissue type on Jul 28, 2025
  4. added a commit that references this issue on Nov 20, 2025
    9e34128
  5. NinoFloris commented on Mar 13, 2026

    @NinoFloris
    Member

    Fixed by #6342

  6. removed this from the Backlog milestone on Mar 13, 2026
  7. added this to the 10.0.0 milestone on Mar 13, 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

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions