Skip to content

XmlAttributeProperties.GetXmlNamespaceMaps throws System.InvalidCastException #1583

@etvorun

Description

@etvorun

Repro:

  1. Create WPF Core app in Visual Studio
  2. Open MainWindow.xaml.cs and add following code to MainWindow constructor
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                string maps = XmlAttributeProperties.GetXmlNamespaceMaps(this);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
            }
        }
        
  1. Build and run.
    Expected: no assert dialogs
    Actual: assert dialog
System.InvalidCastException: Unable to cast object of type 'System.Collections.Hashtable' to type 'System.String'
   at System.Windows.Markup.XmlAttributeProperties.GetXmlNamespaceMaps(DependencyObject dependencyObject)
   at WpfApp.MainWindow in MainWindow.xaml.cs

Note: looks like incorrect DP declaration:
[https://github.com/dotnet/wpf/blob/ae1790531c3b993b56eba8b1f0dd395a3ed7de75/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlAttributeProperties.cs]

XmlNamespaceMapsProperty = DependencyProperty.RegisterAttached("XmlNamespaceMaps", **typeof(Hashtable)** . . .
public static string GetXmlNamespaceMaps(DependencyObject dependencyObject)
{ . . .  return **(string)**dependencyObject.GetValue(XmlNamespaceMapsProperty);

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions