You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MvvmCross从5.7升级到6.0.0时创建Setup实例失败求助

Fix: "Failed to create setup instance" when upgrading MvvmCross from 5.7 to 6.0.0

I’ve seen this exact issue pop up a lot with MvvmCross 6.0 upgrades—this version made breaking changes to Android’s setup and launch flow, which is almost certainly what’s tripping you up. Let’s walk through the fixes step by step:

1. Update your Setup class inheritance

MvvmCross 6.0 moved to using AppCompat-based setup by default. Your old MvxAndroidSetup won’t work anymore—you need to switch to MvxAppCompatSetup:

Old (broken) Setup code:

public class Setup : MvxAndroidSetup<App>
{
    // ... your old implementation
}

New (fixed) Setup code:

using MvvmCross.Droid.Support.V7.AppCompat;
using Android.Content;

public class Setup : MvxAppCompatSetup<Core.App>
{
    public Setup(Context applicationContext) : base(applicationContext)
    {
    }

    protected override IMvxApplication CreateApp()
    {
        return new Core.App();
    }
}

2. Fix your launch Activity & Application class

Your main launcher Activity needs to inherit from MvxAppCompatActivity instead of the old MvxActivity, and you should also ensure your Application class uses the AppCompat base.

First, update your Application class

Create or modify your Android Application class to use MvxAppCompatApplication:

using MvvmCross.Droid.Support.V7.AppCompat;

namespace ClaveiSGApp.Droid
{
    public class ClaveiSGAppApplication : MvxAppCompatApplication<Setup, Core.App>
    {
    }
}

Then update your AndroidManifest.xml to point to this class:

<application android:name=".ClaveiSGAppApplication" 
             android:label="App" 
             android:theme="@style/AppTheme">
    <!-- ... other manifest entries -->
</application>

Update your launcher Activity

Here’s a corrected example of your launcher Activity (splash or main):

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

namespace ClaveiSGApp.Droid.Views
{
    [Activity(Label = "App", 
              MainLauncher = true, 
              Theme = "@style/AppTheme.Splash",
              NoHistory = true)]
    public class SplashActivity : MvxAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            
            // Navigate to your main activity after splash
            StartActivity(typeof(MainActivity));
            Finish();
        }
    }

    [Activity(Label = "App")]
    public class MainActivity : MvxAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
        }
    }
}

3. Clean up NuGet packages

Make all MvvmCross-related NuGet packages are on version 6.0.0—mixing versions (even accidentally) will cause this error. Check these packages specifically:

  • MvvmCross
  • MvvmCross.Droid.Support.V7.AppCompat
  • MvvmCross.Platforms.Android

4. Clear build cache and rebuild

Sometimes old build artifacts cause issues after major upgrades:

  1. Go to Build > Clean Solution
  2. Delete the bin and obj folders in your Android project
  3. Rebuild the solution
  4. Restart Visual Studio 2017 to clear any lingering cache

If you’re still stuck...

Add debug logging or exception handling in your Setup class to get more details about what’s failing:

protected override void InitializeFirstChance()
{
    // Add a breakpoint here or log to console
    System.Diagnostics.Debug.WriteLine("Setup initializing...");
    base.InitializeFirstChance();
}

This will help you pinpoint if the issue is with app creation, service registration, or something else.

内容的提问来源于stack exchange,提问作者Brugui

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:31:58