MvvmCross.Exceptions.MvxException: 创建设置实例失败

MvvmCross.Exceptions.MvxException: Failed to create setup instance

我正在从 MvvMCross 5.7 升级到 6.0.0。

当我尝试 运行 应用程序时,它显示启动画面,紧接着,vs2017 给我以下错误:

MvvmCross.Exceptions.MvxException: Failed to create setup instance

错误总是在同一行,无论我将哪个文件设置为 mainlauncher。

示例:

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);
        }
    }
}

错误总是在base.OnCreate(bundle);

你有什么想法吗?

(如果您需要更多 info/code 的信息,请告诉我)

从您收到的错误来看,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) 中的 CreateSetup 方法似乎发生了错误。追踪注册发生的位置,它给了我两个可能的地方:MvxSplashScreenActivity<TMvxAndroidSetup, TApplication>MvxAndroidApplication<TMvxAndroidSetup, TApplication>.

继续这种想法,并假设您确实在您的应用中使用了 SplashScreen。我建议更新您的 SplashScreen activity 以继承自 MvxSplashScreenActivity<TMvxAndroidSetup, TApplication> 并检查是否有帮助 - 您还需要将 SplashScreen 设置为 MainLauncher。您的代码可能如下所示:

[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);
    }
}

如果以上内容不清楚,请查看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,以及我粘贴的示例代码

几天后,搜索、查看 gihub 文件并按照@Ale_lipa 的建议与 Nick Randolph 交谈。

我注意到问题出在.Droid 项目下的.csproj 文件上。它试图编译我从项目中手动删除的文件,这些文件甚至不存在。

我更改了它以匹配 Nick 在 his repository 中的文件。

这是最后的样子:

<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>

现在一切正常。

我按照其他答案中引用的 blog post series by Nick Randolph 的确切步骤进行操作,并收到与问题指定 [Failed to create setup instance] 相同的问题,但在 Xamarin.Forms 文章中。这是由于混合了来自示例不同部分的代码。我的具体问题是因为声明 MainLauncher=true 派生自 MvxFormsAppCompatActivity<TViewModel> 而不是 MvxFormsAppCompatActivity<TMvxAndroidSetup, TApplication, TFormsApplication, TViewModel>ActivityAttribute 看起来 OP @Brugui 示例代码可能具有相同的缺陷。