WPF and Unity - No matching constructor found on type WPF and Unity - No matching constructor found on type wpf wpf

WPF and Unity - No matching constructor found on type


In your App.xaml, make sure that you have gotten rid of the StartupUri="MainWindow.xaml" property being set. Since you have overriden the OnStartup of your application and provided a custom instance of the MainWindow you shouldn't be leaving the default StartupUri property being set in the App.xaml file and WPF desperately trying to instantiate a type without a default constructor.


To complement the excellent answer, after deleting the startup URI don't forget to call the startup method within your App.xaml declaration:

<Application x:Class="Test.App"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             xmlns:local="clr-namespace:Test.App"             Startup="Application_Startup">    <Application.Resources>             </Application.Resources></Application>

public partial class App : Application    {        public IContainer container { get; private set; }        private void Application_Startup(object sender, StartupEventArgs e)        {            var dependencyConfigurator = new DependencyConfig();            container = dependencyConfigurator.Configure();            container.Resolve<WindowClassName>();            MainWindow.Show();        }            }