Skip to content

Document GetXamlType null Type exception - #12997

Open
gewarren with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-null-reference-in-getxamltype
Open

Document GetXamlType null Type exception#12997
gewarren with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-null-reference-in-getxamltype

Conversation

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

XamlSchemaContext.GetXamlType(Type) currently throws NullReferenceException when called with a null Type, while the API docs listed ArgumentNullException.

  • API docs
    • Updated the GetXamlType(Type) exception documentation to match observed runtime behavior.
    • Changed the null type exception from ArgumentNullException to NullReferenceException.
var context = new XamlSchemaContext();
context.GetXamlType((Type)null); // throws NullReferenceException

Internal previews

File Preview link
xml/System.Xaml/XamlSchemaContext.xml Preview published page

Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix NullReferenceException in XamlSchemaContext.GetXamlType Document GetXamlType null Type exception Aug 18, 2026
Copilot AI requested a review from gewarren August 18, 2026 00:51
@gewarren
gewarren marked this pull request as ready for review August 18, 2026 00:59
@gewarren
gewarren requested a review from a team as a code owner August 18, 2026 00:59
Copilot AI lite review requested due to automatic review settings August 18, 2026 00:59
@gewarren
gewarren enabled auto-merge (squash) August 18, 2026 01:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the System.Xaml API reference documentation for XamlSchemaContext.GetXamlType(Type) to reflect the currently observed exception thrown when a null Type is provided.

Changes:

  • Updated the documented null-argument exception for GetXamlType(Type) from ArgumentNullException to NullReferenceException.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread xml/System.Xaml/XamlSchemaContext.xml Outdated

@wadepickett wadepickett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gewarren: I tried looking up the exception we are trying to document here in the source but didn't find what was expected. The current .NET source code throws ArgumentNullException, not NullReferenceException, when GetXamlType(Type) is called with a null type. The premise of the PR might be incorrect and might need a closer look. Maybe this is for a future change not yet merged to the main branch? Could be I have this wrong. Here is a link to the source:
https://github.com/dotnet/wpf/blob/1346571efc19a83a90edf3abe9059d18f8412cdb/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedXamlSchemaContext.cs#L18-L20

@gewarren

Copy link
Copy Markdown
Collaborator

@gewarren: I tried looking up the exception we are trying to document here in the source but didn't find what was expected. The current .NET source code throws ArgumentNullException, not NullReferenceException, when GetXamlType(Type) is called with a null type. The premise of the PR might be incorrect and might need a closer look. Maybe this is for a future change not yet merged to the main branch? Could be I have this wrong. Here is a link to the source: https://github.com/dotnet/wpf/blob/1346571efc19a83a90edf3abe9059d18f8412cdb/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedXamlSchemaContext.cs#L18-L20

Thanks @wadepickett. That is a different, internal type, but I checked for modern .NET versions and yes, it does appear to throw ANE. @adegeo Do you know where the source code is for .NET Framework 4.7.2 for this method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XamlSchemaContext.GetXamlType((Type)null) throws NRE

4 participants