Skip to content

NpgsqlConnectionStringBuilder ICustomTypeDescriptor implementation broken since version 8.x #6289

@lorenz-mgutt

Description

@lorenz-mgutt

We are using the ICustomTypeDescriptor interface of NpgsqlConnectionStringBuilder to retrieve the connection properties like:

var builder = new NpgsqlConnectionStringBuilder();
var properties = ((ICustomTypeDescriptor)builder).GetProperties().Cast<PropertyDescriptor>()

Since version 8.x onward this implementation is broken by a refactoring of the DbConnectionStringBuilder.GetProperties override:

NpgSql Version 7.0.10 - works fine:

protected override void GetProperties(Hashtable propertyDescriptors)
    {
        // Tweak which properties are exposed via TypeDescriptor. This affects the VS DDEX
        // provider, for example.
        base.GetProperties(propertyDescriptors);

        var toRemove = propertyDescriptors.Values
            .Cast<PropertyDescriptor>()
            .Where(d =>
                !d.Attributes.Cast<Attribute>().Any(a => a is NpgsqlConnectionStringPropertyAttribute) ||
                d.Attributes.Cast<Attribute>().Any(a => a is ObsoleteAttribute)
            )
            .ToList();
        foreach (var o in toRemove)
            propertyDescriptors.Remove(o.DisplayName);
    }

NpgSql Version 8.0.0 onwards is broken since it filters out all properties having the NpgsqlConnectionStringPropertyAttribute instead of keeping exact those:

    protected override void GetProperties(Hashtable propertyDescriptors)
    {
        // Tweak which properties are exposed via TypeDescriptor. This affects the VS DDEX
        // provider, for example.
        base.GetProperties(propertyDescriptors);

        var toRemove = new List<PropertyDescriptor>();
        foreach (var value in propertyDescriptors.Values)
        {
            var d = (PropertyDescriptor)value;
            foreach (var attribute in d.Attributes)
                if (attribute is NpgsqlConnectionStringPropertyAttribute or ObsoleteAttribute)
                    toRemove.Add(d);
        }

        foreach (var o in toRemove)
            propertyDescriptors.Remove(o.DisplayName);
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions