XamlParseException: No matching constructor found on type

Today in this article, we will cover below aspects,

Issue Description

WPF application runtime gives below error,

System.Windows.Markup.XamlParseException
Message=’No matching constructor found on type MissingMethodException: No default constructor found for type ‘WPFDesktopApp.EmployeeWindow’. You can use the Arguments or FactoryMethod directives to construct this type.

XamlParseException No matching constructor found on type

Resolution

This issue is more visible when you try to provide a custom instance of the Window object.

For Example, The issue is common when the target Window is being instantiated with parameterized constructor etc.

 public partial class EmployeeWindow : Window
    {

        private readonly IEmployeeViewModel _businessObject;
        public EmployeeWindow(IEmployeeViewModel business)
        {
            InitializeComponent();
            _businessObject = business;

        }
...

   }

In such cases, please remove default StartupUri property being set in the App.xaml file.

XamlParseException No matching constructor found on type

The issue resolves once the above line is removed.

Did I miss anything else in these resolution steps?

Did the above steps resolve your issue? Please sound off your comments below!

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *