Skip to content

Null Reference Exception from QuantityTypeConverter #755

@WalkerCodeRanger

Description

@WalkerCodeRanger

Describe the bug
If the PropertyDescriptor property of the context which is invoking QuantityTypeConverter<T>.ConvertFrom() is null, it throws a NullReferenceException.

To Reproduce

var converter = new QuantityTypeConverter<Length>();
// TypeDescriptorContext with null `PropertyDescriptor` property
ITypeDescriptorContext context = new TypeDescriptorContext();
Length length = Length.FromMeters(1);

string convertedQuantity = (string)converter.ConvertTo(context, culture, length, typeof(string));

Expected behavior
No exception should be thrown. The conversion should be done as if there were a property with no attributes.

Additional context
In our codebase, this is happening indirectly through the System.Activities.Presentation.WorkflowDesigner.PropertyInspectorView. Also, the ITypeDescriptorContext.PropertyDescriptor docs explicitly state that this property "describes the given context item; otherwise, null if there is no PropertyDescriptor responsible for the call."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions