Skip to content

XamlSchemaContext.GetXamlType((Type)null) throws NRE #205

@hughbe

Description

@hughbe

This doesn't match the docs: https://docs.microsoft.com/en-us/dotnet/api/system.xaml.xamlschemacontext.getxamltype?view=netframework-4.7.2#System_Xaml_XamlSchemaContext_GetXamlType_System_Type_

Example test:

[Fact]
public void GetXamlType_NullXamlType_ThrowsNullReferenceException()
{
    var context = new XamlSchemaContext();
    Assert.Throws<NullReferenceException>(() => context.GetXamlType((Type)null));
}

Problematic code:

public virtual XamlType GetXamlType(Type type)
{
    return GetXamlType(type, XamlLanguage.TypeAlias(type)); // <-- NRE thrown in TypeAlias
}

internal XamlType GetXamlType(Type type, string alias)
{
    if (type == null)
    {
        throw new ArgumentNullException(nameof(type));
    }
    XamlType xamlType = null;
    if (!MasterTypeList.TryGetValue(type, out xamlType))
    {
        xamlType = new XamlType(alias, type, this, null, null);
        xamlType = TryAdd(MasterTypeList, type, xamlType);
    }
    return xamlType;
}

Should the code be updated, or the docs? I can fix the code if requested!

Metadata

Metadata

Assignees

Labels

BugProduct bug (most likely)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions