NpgsqlParameterCollection.Clear() doesn't reset NpgsqlParameter.Collection #231

FransBouma opened this Issue May 7, 2014 · 3 comments


None yet

2 participants


See also the dev mailing list.

var p = new NpgsqlParameter();
var c1 = new NpgsqlCommand();
var c2 = new NpgsqlCommand();
c2.Parameters.Add(p); // <<<<<<<< crash

This is because NpgsqlParameterCollection.Clear() doesn't reset parameter.Collection on the parameters it removes:

    /// <summary>
    /// Removes all items from the collection.
    /// </summary>
    public override void Clear()
        NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Clear");

This thus causes problems when parameters have to be moved to another Command because two commands are merged into 1 query.


Updated :)

@franciscojunior franciscojunior added this to the 2.2 milestone May 8, 2014
@franciscojunior franciscojunior added the bug label May 8, 2014

Fixed by #234 .

@drunaar drunaar added a commit to drunaar/Npgsql that referenced this issue May 14, 2014
@FransBouma @drunaar FransBouma + drunaar Fixes for issue #231
See: npgsql#231

Fixed the issue by implementing proper clean up in the Clear() method.
Cleaned up the Remove methods in NpgsqlParameterCollection as they
re-implemented the same code 6 times (Remove and RemoveAt+overloads).
Now all end up in 1 Remove method which performs the remove and the
parameter cleanup. Easier to maintain ;)
Added a test to verify my fix. Please verify the Remove changes as I
can't run the rest of the tests.

2.2.3 has this problem again. See PR #234

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