I'm trying to create a simple IoC/DI scenario following this guide.
Note: I religiously followed every step, but still to no avail.
I'm getting this error:
System.Windows.Markup.XamlParseException: 'No matching constructor found on type 'TestMef.Pages.Settings.Appearance'. You can use the Arguments or FactoryMethod directives to construct this type.' Line number '19' and line position '6'. ---> System.MissingMethodException: No default constructor found for type 'TestMef.Pages.Settings.Appearance'. You can use the Arguments or FactoryMethod directives to construct this type.
at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.EnsureConstructorDelegate(XamlTypeInvoker type)
at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CreateInstance(XamlTypeInvoker type)
at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
--- End of inner exception stack trace ---
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.LoadComponent(Uri resourceLocator)
at FirstFloor.ModernUI.Windows.DefaultContentLoader.LoadContent(Uri uri)
at FirstFloor.ModernUI.Windows.DefaultContentLoader.<>c__DisplayClass0_0.<LoadContentAsync>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
Page with constructor parameter (DI via MEF):
[ContentExport("/Pages/Settings/Appearance")]
public partial class Appearance : UserControl, IContent
{
[ImportingConstructor]
public Appearance(IAppearanceViewModel vm) //<= Why the cause of Error? While other parameterless pages are working just fine.
{
InitializeComponent();
DataContext = vm;
}
public void OnFragmentNavigation(FragmentNavigationEventArgs e){ }
public void OnNavigatedFrom(NavigationEventArgs e){ }
public void OnNavigatedTo(NavigationEventArgs e){ }
public void OnNavigatingFrom(NavigatingCancelEventArgs e){}
}
//ViewModel decalaration (in a separate file)
[Export(typeof(IAppearanceViewModel))]
public class AppearanceViewModel
: NotifyPropertyChanged, IAppearanceViewModel
{
//skipped contents for brevity
}
Hi,
I'm trying to create a simple IoC/DI scenario following this guide.
I'm getting this error:
Page with constructor parameter (DI via MEF):
App.xaml:
AppResources.xaml:
MefContentLoader:
Please advise.
Thank you in advance.