Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySqlConnectionStringBuilder does not implement ICustomTypeDescriptor correctly #1030

Closed
masonwheeler opened this issue Sep 9, 2021 · 10 comments
Labels
Milestone

Comments

@masonwheeler
Copy link

DbConnectionStringBuilder, the base class for connection string builders, implements ICustomTypeDescriptor so that the class can interface properly with UI inspector components such as the WinForms PropertyGrid or the various property grid implementations available on WPF.

When attempting to inspect a MySqlConnectionStringBuilder to one of these, it does not display the values properly; everything displays as a null value regardless of whether or not the property actually has a value.

@bgrainger
Copy link
Member

The background to this request is in this SO question and the extended discussion in the comments: https://stackoverflow.com/questions/69080255/why-do-dbconnectionstringbuilder-descendants-break-property-grid-binding-so-thor

@bgrainger
Copy link
Member

@masonwheeler From related issues you've posted and SO questions, it sounds like you might have already built a test harness that demonstrates the problem (with various property grids); do you have sample code that reproduces this problem available?

@bgrainger
Copy link
Member

bgrainger commented Sep 9, 2021

Is the fundamental issue here that connectionStringBuilder.TryGetValue("PropName", out var value) always returns false for MySqlConnector? No, because that's not true.

@bgrainger
Copy link
Member

Still not sure what the bug here is. This code works fine with MySqlConnector:

var csb = new MySqlConnectionStringBuilder();
csb.MinimumPoolSize = 5;

ICustomTypeDescriptor td = csb;
td.GetProperties().Cast<PropertyDescriptor>().Count(x => x.DisplayName == "Minimum Pool Size"); // 1
csb.ContainsKey("Minimum Pool Size"); // true
csb.TryGetValue("Minimum Pool Size", out var value); // true, 5

Interestingly, in Connector/NET that code returns 1, true, false / null, which seems like a bug.

@bgrainger
Copy link
Member

OK, I'm seeing a problem. ((ICustomTypeDescriptor) csb).GetProperties() returns a property named MinimumPoolSize. However once the MinimumPoolSize C# property is set, it also returns Minimum Pool Size in that collection. Retrieving the property using the name with spaces works, but using the name without spaces doesn't work.

Oracle's Connector/NET always fails for TryGetValue but can return the value via csb["Prop Name"] (which also works in MySqlConnector). The bug appears to be that property names are incorrect when returned from ICustomTypeDescriptor.

@masonwheeler
Copy link
Author

@bgrainger Here's a very simple repro case.

@masonwheeler
Copy link
Author

Very nice work, especially adding the categories. That makes it much more readable in the editor.

Can you ping me on here when a new version is up on NuGet?

@bgrainger
Copy link
Member

Yep; I'll need your feedback on whether this has resolved the issue, or if additional work is needed.

@bgrainger
Copy link
Member

@masonwheeler Please try 1.4.0-beta.3 and let me know if this is fixed! https://www.nuget.org/packages/MySqlConnector/1.4.0-beta.3

@masonwheeler
Copy link
Author

Yes, this appears to be fixed. Thanks for getting this taken care of so quickly!

@bgrainger bgrainger added this to the 2.0 milestone Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants