Mvvmcross: Xamarin Forms 3.4 not working with WPF

Created on 19 Dec 2018  路  7Comments  路  Source: MvvmCross/MvvmCross

馃悰 Bug Report

I have created a project using MvvmCross 6.2.2 from Nuget and Xamarin.Forms 3.4 from nuget. For easier testing I am using a WPF Xamarin Forms application.

Whenever i try to run my application I get the error Method not found: 'Void Xamarin.Forms.Forms.Init() as soon as I start my application.

StackTrace:

"   at MvvmCross.Forms.Platforms.Wpf.Core.MvxFormsWpfSetup.get_FormsApplication()\r\n   at MvvmCross.Forms.Platforms.Wpf.Core.MvxFormsWpfSetup.CreateViewPresenter(ContentControl contentControl) in C:\\projects\\mvvmcross\\MvvmCross.Forms.Wpf\\Platforms\\Wpf\\Core\\MvxFormsWindowsSetup.cs:line 57\r\n   at MvvmCross.Platforms.Wpf.Core.MvxWpfSetup.get_Presenter() in C:\\projects\\mvvmcross\\MvvmCross\\Platforms\\Wpf\\Core\\MvxWpfSetup.cs:line 73\r\n   at MvvmCross.Platforms.Wpf.Core.MvxWpfSetup.RegisterPresenter() in C:\\projects\\mvvmcross\\MvvmCross\\Platforms\\Wpf\\Core\\MvxWpfSetup.cs:line 90\r\n   at MvvmCross.Platforms.Wpf.Core.MvxWpfSetup.InitializePlatformServices() in C:\\projects\\mvvmcross\\MvvmCross\\Platforms\\Wpf\\Core\\MvxWpfSetup.cs:line 48\r\n   at MvvmCross.Core.MvxSetup.InitializePrimary() in C:\\projects\\mvvmcross\\MvvmCross\\Core\\MvxSetup.cs:line 74\r\n   at MvvmCross.Core.MvxSetupSingleton.StartSetupInitialization() in C:\\projects\\mvvmcross\\MvvmCross\\Core\\MvxSetupSingleton.cs:line 181\r\n   at MvvmCross.Core.MvxSetupSingleton.EnsureInitialized() in C:\\projects\\mvvmcross\\MvvmCross\\Core\\MvxSetupSingleton.cs:line 102\r\n   at MvvmCross.Forms.Platforms.Wpf.Views.MvxFormsWindowsPage.RunAppStart(Object hint) in C:\\projects\\mvvmcross\\MvvmCross.Forms.Wpf\\Platforms\\Wpf\\Views\\MvxFormsWindowsPage.cs:line 45\r\n   at MvvmCross.Forms.Platforms.Wpf.Views.MvxFormsWindowsPage.MvxWindow_Initialized(Object sender, EventArgs e) in C:\\projects\\mvvmcross\\MvvmCross.Forms.Wpf\\Platforms\\Wpf\\Views\\MvxFormsWindowsPage.cs:line 40\r\n   at System.Windows.FrameworkElement.RaiseInitialized(EventPrivateKey key, EventArgs e)\r\n   at System.Windows.FrameworkElement.OnInitialized(EventArgs e)\r\n   at System.Windows.FrameworkElement.TryFireInitialized()\r\n   at System.Windows.FrameworkElement.EndInit()\r\n   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)"

By downgrading Xamarin.Forms to 3.1 I was able to run the solution correctly

Expected behavior

App should run normally with Xamarin.Forms 3.4

Configuration

Version: 6.2.2

Platform:

  • [ ] :iphone: iOS
  • [ ] :robot: Android
  • [x] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [X] :monkey: Xamarin.Forms
needs-investigation up-for-grabs

All 7 comments

@mattiascibien do you have a few minutes where you can run up the Playground app in the source and see whether you can a) reproduce the issue and b) perhaps spot a fix?

@nickrandolph Unfortunately at the moment I am at work. I'll try to look as soon as I get home or maybe this weekend.

Hi, I have also been experiencing this issue. The application cannot initialize as it hits the error "Method not found: Void Xamarin.Forms.Forms.Init()". However it runs fine on xamarin.forms 3.2 and below but I need 3.4. Have there been any findings for a solution?

Sorry. I did not have time to investigate the issue. I鈥檒l try to check this weekend.

I fixed this issue by overriding MvxFormsWpfSetup.FormsApplication

    public abstract class MyWpfSetup<TApplication> : MvxFormsWpfSetup<TApplication, ErxFormsApplication>
        where TApplication : class, IMvxApplication, new()
    {
        private Application _formsApplication;

        public override Application FormsApplication
        {
            get
            {
                if (!Xamarin.Forms.Forms.IsInitialized)
                    Xamarin.Forms.Forms.Init();

                if (_formsApplication == null)
                    _formsApplication = CreateFormsApplication();
                if (Application.Current != _formsApplication)
                    Application.Current = _formsApplication;

                return _formsApplication;
            }
        }
    }

@rhussell Fantastic, works for me. Thanks :)

MvvmCross is updated to Forms 3.6 so this should not happen anymore. Please reopen or open another issue if it does.

Was this page helpful?
0 / 5 - 0 ratings