Document GetXamlType null Type exception - #12997
Conversation
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
There was a problem hiding this comment.
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)fromArgumentNullExceptiontoNullReferenceException.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wadepickett
left a comment
There was a problem hiding this comment.
@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? |
|
Browsing the source reference in a .NET Framework project shows the following code: public virtual XamlType GetXamlType(Type type)
{
return GetXamlType(type, XamlLanguage.TypeAlias(type));
}
internal XamlType GetXamlType(Type type, string alias)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
XamlType value = null;
if (!MasterTypeList.TryGetValue(type, out value))
{
value = new XamlType(alias, type, this, null, null);
value = TryAdd(MasterTypeList, type, value);
}
return value;
}I don't know where this |
|
Apparently the call to Considering this is thrown 100% by the bug, I think it's safe to document as a .NET Framework and up until .NET 5. Looking at the dates, this was fixed a month before .NET 6 was released. |
XamlSchemaContext.GetXamlType(Type)currently throwsNullReferenceExceptionwhen called with a nullType, while the API docs listedArgumentNullException.GetXamlType(Type)exception documentation to match observed runtime behavior.typeexception fromArgumentNullExceptiontoNullReferenceException.Internal previews