Brugui
Brugui

Reputation: 574

MvvmCross.Exceptions.MvxException: Failed to create setup instance

I'm upgrading from MvvMCross 5.7 to 6.0.0.

When I try to run the app, it shows the splash screen and just after that, vs2017 gives me the following error:

MvvmCross.Exceptions.MvxException: Failed to create setup instance

The error always is in the same line, no matter which file I set as mainlauncher.

Example:

using Android.App;
using Android.OS;
using MvvmCross.Droid.Support.V7.AppCompat;
using MvvmCross.Platforms.Android.Views;

namespace ClaveiSGApp.Droid.Views
{
    [Activity(Label = "App", MainLauncher = true)]
    public class MainView : MvxAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.MainView);
        }
    }
}

The error always is in base.OnCreate(bundle);

Do you have any ideas?

(Let me know if you need more info/code about something)

Upvotes: 3

Views: 2061

Answers (3)

Steven Bone
Steven Bone

Reputation: 598

I followed the exact steps on the blog post series by Nick Randolph referenced in other answers, and received the same problem as the question specifies [Failed to create setup instance] but in the Xamarin.Forms article. This was due to mixing code from a different part of the example. My specific issue was because the ActivityAttribute that declared MainLauncher=true derived from MvxFormsAppCompatActivity<TViewModel> instead of MvxFormsAppCompatActivity<TMvxAndroidSetup, TApplication, TFormsApplication, TViewModel> Looks like the OP @Brugui sample code may have had the same flaw.

Upvotes: 1

Mikolaj Kieres
Mikolaj Kieres

Reputation: 4405

From the error you're getting, it looks like something bad is happening in CreateSetup method in MvxSetupSingleton (GitHub). I'm guessing here a bit, but I would assume that there's something wrong with how the RegisterSetupType<TMvxSetup> is being called (or it's not being called at all) - you can find this method in MvxSetup (GitHub). Tracking down where the registration happens, it gave me two possible places: MvxSplashScreenActivity<TMvxAndroidSetup, TApplication> and MvxAndroidApplication<TMvxAndroidSetup, TApplication>.

Going forward with this thinking, and assuming you do use SplashScreen in your app. I would suggest updating your SplashScreen activity to inherit from MvxSplashScreenActivity<TMvxAndroidSetup, TApplication> and check if that helps - you would also need to make your SplashScreen is MainLauncher. Your code could look like this:

[Activity(Label = "FirstDemo.Forms.Splash", Theme = "@style/MainTheme",  MainLauncher = true, NoHistory = true)]
public class SplashScreen : MvxFormsSplashScreenAppCompatActivity<MvxFormsAndroidSetup<Core.App, App>, Core.App, App>
{
    public SplashScreen()
         : base(Resource.Layout.SplashScreen)
    {
    }

    protected override void RunAppStart(Bundle bundle)
    {
        StartActivity(typeof(MainActivity));
        base.RunAppStart(bundle);
    }
}

If the above is not clear, check out blog post by Nick Randolph (a contributor to MvvmCross), that writes about setting up a brand new project with MvvmCross v6. I know you're upgrading - so it's not the same, but you can at least check if you have made all the changes that are required to run the app. Here's his GitHub repo, with the sample code that I pasted in

Upvotes: 3

Brugui
Brugui

Reputation: 574

After I few days, searching, seeing gihub files and talking with Nick Randolph as @Ale_lipa suggested.

I noticed that the problem was on the .csproj file under the .Droid project. It was trying to compile files that I manually removed from the project and didn't even exist.

I changed it to match the file that Nick has in his repository.

This is the final look:

<ItemGroup>
    <Compile Include="SplashScreen.cs" />
    <Compile Include="MainApplication.cs" />
    <Compile Include="Resources\Resource.Designer.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Views\FirstView.cs" />
</ItemGroup>

Now everything works fine.

Upvotes: 1

Related Questions