When NpgSqlCommand is created with a string that contains escaped apostrophe, the parameters in the query after this string are not substitued even though the valid values are provided. Such parameters placed before the string with apostrophe are substitued correctly.
Following example creates a SQL "INSERT INTO TestTable (StringColumn, ByteaColumn) VALUES ('b''la', @someValue)" - the SomeValue is not substitued for the provided parameter value. If the @someValue would be placed before the 'b''la' string, everything would work.
using (var cmd = DbConnection.CreateCommand())
{
cmd.CommandText = "INSERT INTO TestTable (StringColumn, ByteaColumn) VALUES ('b''la', @SomeValue)";
cmd.Parameters.AddWithValue("SomeValue", new byte[] { 1, });
cmd.ExecuteNonQuery();
}