MvvmCross: Upgrade to version 8.0.2 failed to resolve IMvxMessenger on start
🔙 Regression
After upgrading from 7.x to version 8.0.2 the app throws a Failed to resolve first ViewModel
Old (and correct) behavior
App starts up normally.
Current behavior
on start throw the following exception
{MvvmCross.Exceptions.MvxException} MvvmCross.Exceptions.MvxException
Exception: "Failed to construct and initialize ViewModel for type CaledosLab.Runner.Commons.ViewModels.MainPageViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information"
at MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.ViewModels.MvxViewModelRequest request, MvvmCross.ViewModels.IMvxBundle savedState, MvvmCross.Navigation.EventArguments.IMvxNavigateEventArgs navigationArgs) [0x00044] in /_/MvvmCross/ViewModels/MvxViewModelLoader.cs:74
at MvvmCross.Navigation.MvxNavigationService.Navigate (System.Type viewModelType, MvvmCross.ViewModels.IMvxBundle presentationBundle, System.Threading.CancellationToken cancellationToken) [0x00019] in /_/MvvmCross/Navigation/MvxNavigationService.cs:454
at MvvmCross.Navigation.MvxNavigationService.Navigate[TViewModel] (MvvmCross.ViewModels.IMvxBundle presentationBundle, System.Threading.CancellationToken cancellationToken) [0x00000] in /_/MvvmCross/Navigation/MvxNavigationService.cs:501
at CaledosLab.Runner.Commons.ViewModels.CaledosAppStart.NavigateToFirstViewModel (System.Object hint) [0x00018] in C:\Caledos\code\Runner\CaledosLab.Runner.Commons.ViewModels\App.cs:53
InnerException {MvvmCross.Exceptions.MvxException} MvvmCross.Exceptions.MvxException
Message "Problem creating viewModel of type MainPageViewModel"
at MvvmCross.ViewModels.MvxDefaultViewModelLocator.Load (System.Type viewModelType, MvvmCross.ViewModels.IMvxBundle parameterValues, MvvmCross.ViewModels.IMvxBundle savedState, MvvmCross.Navigation.EventArguments.IMvxNavigateEventArgs navigationArgs) [0x00029] in /_/MvvmCross/ViewModels/MvxDefaultViewModelLocator.cs:32
at MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.ViewModels.MvxViewModelRequest request, MvvmCross.ViewModels.IMvxBundle savedState, MvvmCross.Navigation.EventArguments.IMvxNavigateEventArgs navigationArgs) [0x00031] in /_/MvvmCross/ViewModels/MvxViewModelLoader.cs:70
InnerException {MvvmCross.Exceptions.MvxIoCResolveException} MvvmCross.Exceptions.MvxIoCResolveException
Message "Problem creating viewModel of type MainPageViewModel" string
at MvvmCross.ViewModels.MvxDefaultViewModelLocator.Load (System.Type viewModelType, MvvmCross.ViewModels.IMvxBundle parameterValues, MvvmCross.ViewModels.IMvxBundle savedState, MvvmCross.Navigation.EventArguments.IMvxNavigateEventArgs navigationArgs) [0x00029] in /_/MvvmCross/ViewModels/MvxDefaultViewModelLocator.cs:32
at MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.ViewModels.MvxViewModelRequest request, MvvmCross.ViewModels.IMvxBundle savedState, MvvmCross.Navigation.EventArguments.IMvxNavigateEventArgs navigationArgs) [0x00031] in /_/MvvmCross/ViewModels/MvxViewModelLoader.cs:70
Reproduction steps
the exception raises here(***)
public class App : MvvmCross.ViewModels.MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();
InitializeAppConfiguration();
InitializeAppText();
RegisterCustomAppStart<CaledosAppStart>();
}
private void InitializeAppConfiguration()
{
var languageManager = new LanguageManager();
Mvx.IoCProvider.RegisterSingleton<ILanguageManager>(languageManager);
}
private void InitializeAppText()
{
TextLoader.Instance.LoadJsonFromResource("Shared.json", "Shared");
}
}
public class CaledosAppStart : MvxAppStart
{
public CaledosAppStart(IMvxApplication application, IMvxNavigationService navigationService) : base(application, navigationService)
{
}
protected override async Task NavigateToFirstViewModel(object hint = null)
{
try
{
await NavigationService.Navigate<MainPageViewModel>();
}
catch (System.Exception e)
{
throw; (***)
}
}
}
Configuration
Version: 8.0.2
Platform:
- 🤖 Android
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 16 (10 by maintainers)
Solved the problem by adding this to
App.Initialize()before registering any of my singletons and callingRegisterAppStart<…>():@ivmirx