Hi,
I am using Prism with Autofac for my UWP App.
In my Views I set the mvvm:ViewModelLocator.AutoWireViewMode="True".
While developing it can happen that my ViewModels cannot be resolved from the Autofac container because I missed something (like missing registration or something).
If I now try to open the View I get a Windows.UI.Xaml.Markup.XamlParseException with the message _'Failed to assign to property 'Prism.Windows.Mvvm.ViewModelLocator.AutoWireViewModel''_.
The problem is that no other information can be get from this exception.
Is there any chance that I can get the underlying Autofac exception which says why my ViewModel can't be resolved? Or am I doing something wrong so that I dont get this exception?
Thank you for your help.
This is behavior we see a lot on UWP. We'll have to look deeper into this to see if we can provide you with more info.
I've found the easiest way to get a useful error is to do the following
In your request navigate add the following (adapt to your own needs)
_regionManager.RequestNavigate(
_regionName, pageName, nr =>
{
if ( nr.Result.HasValue && nr.Result == false )
{
var error = nr.Error;
}
} );
}
If you put a breakpoint just after var error you can then view what the actual error is there.
edit to say that this works in WPF, don't know if it'll do what you want with UWP.
We experience a startup crash of our UWP app when build in release with .net native, but only on a hosted build agent in visual studio team services. On the local machines it builds and starts without a crash.
I used windbg to narrow it down and the error message is:
Failed to assign to property 'Prism.Windows.Mvvm.ViewModelLocator.AutoWireViewModel'
Any idea why this could happen on a build agent machine and not on developer machines. Same code base and same configuration from what we can see.
Just as a hint for other newbies like me, because there is no message. My mistake was i had not registered all types required to instantiate the view model and the the types required to instantiate the types for the view model... in the IoC Containter in the app.xaml.cs
Container.RegisterType...
+1 to the comment from @dIeGoLi
Missing dependency mapping was the source of this error (using 6.3 here) from someone not checking in the updated infrastructure registrations.
Thanks for the updates. I'm glad it was figured out.
I'm also experiencing this error. However, it is random. When running in debug mode from VS 2017 most of the time the pages load and run fine; however, rarely (perhaps 1 in 20 compiles) it will fail when navigating from a main page to another page. I'm using WTS. The only common things about the pages that fail and the pages that don't is that the failed pages ARE NOT listed as a NavigationViewItem in the Shell and the failed pages ARE being passed a string object parameter in the _navigationService.Navigate().
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
This is behavior we see a lot on UWP. We'll have to look deeper into this to see if we can provide you with more info.