We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Calling HtmlNode.GetAttributeValue(string name, bool def) method always returns default value in version 1.11.32 of Html Agility Pack.
The problem is with this code in GetAttributeValue(string name, T def) whitch is called with bool as the T type parameter.
TypeConverter converter = TypeDescriptor.GetConverter(typeof(T)); try { if (converter != null && converter.CanConvertTo(htmlAttribute.Value.GetType())) { return (T)converter.ConvertTo(htmlAttribute.Value, typeof(T)); } return (T)(object)htmlAttribute.Value; } catch { return def; }
htmlAttribute.Value is for example "true" of type string. converter is BooleanConverter and calling converter.ConvertTo throws exception:
System.NotSupportedException: 'BooleanConverter' is unable to convert 'System.String' to 'System.Boolean'.
exception is catched by catch block and default value is returned.
The text was updated successfully, but these errors were encountered:
Hello @holatom ,
Thank you for reporting,
I improved the code by using the converter code I'm using in another of my project: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/src/Z.Core/System.Object/Convert/Object.To.cs
Everything seems to look fine with this scenario.
Could you try it and let me know that we fixed the issue correctly?
Best Regards,
Jon
Sorry, something went wrong.
Yes, issue is fixed. Thanks.
Awesome @holatom !
We are glad to hear that the issue is fixed!
Don't hesitate to contact us with any questions, issues, or feedback.
Best regards,
JonathanMagnan
No branches or pull requests
Calling HtmlNode.GetAttributeValue(string name, bool def) method always returns default value in version 1.11.32 of Html Agility Pack.
The problem is with this code in GetAttributeValue(string name, T def) whitch is called with bool as the T type parameter.
htmlAttribute.Value is for example "true" of type string.
converter is BooleanConverter and calling converter.ConvertTo throws exception:
System.NotSupportedException: 'BooleanConverter' is unable to convert 'System.String' to 'System.Boolean'.
exception is catched by catch block and default value is returned.
The text was updated successfully, but these errors were encountered: