Why do I get an error CS0310 when using MvxWpfSetup<Core.App> as RegisterSetupType

Viewed 556

I try to build my first app with MvvmCross, found pretty good explanations in this video put I get error CS0310 when I setup the App.xaml.cs file the way it is shown in the video, as well as it is on the example page of the MvvmCross project page.

using MvvmCross.Core;
using MvvmCross.Platforms.Wpf.Core;
using MvvmCross.Platforms.Wpf.Views;

namespace MvxStarter.Wpf
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : MvxApplication
    {
        protected override void RegisterSetup()
        {
            this.RegisterSetupType<MvxWpfSetup<Core.App>>();
        }
    }
}

I am using MvvmCross.Platforms.Wpf in version 8.0.1 and the error message is:

Error   CS0310  'MvxWpfSetup<App>' must be a non-abstract type with a public parameterless 
constructor in order to use it as parameter 'TMvxSetup' in the generic type or method 
'MvxSetupExtensions.RegisterSetupType<TMvxSetup>(object, params Assembly[])'.

The core class library has .Net Core 5.0 as its target framework and the same goes for the WPF project.

3 Answers

All the MvxSetup derivatives were marked abstract in MvvmCross 8.

You need to create your own Setup class:

public class Setup : MvxWpfSetup<App>
{
}

Then you can register that:

this.RegisterSetupType<Setup>();

The version used was 7.0.0 rather than the newest version. To avoid the problem, degrade the version of the nuget package.

The problem is that, in the new version of the package, the class MvxWpfSetup was made abstract, which can't be passed as a generic type for method RegisterSetupType(). You need to implement the abstract class to use it.

The samples have been updated, but the documentation as of yet, not. As others have mentioned create a Setup.cs class in the Wpf project and at minimum add:

public class Setup : MvxWpfSetup<Core.App>
{
    protected override ILoggerFactory CreateLogFactory()
    {
        throw new NotImplementedException();
    }

    protected override ILoggerProvider CreateLogProvider()
    {
        throw new NotImplementedException();
    }
}

Note that MvxWpfSetup's type here is <Core.App>. Then in your app.xaml.cs you can write:

public partial class App : MvxApplication
{
    protected override void RegisterSetup()
    {
        this.RegisterSetupType<Setup>();
    }
}

See the example here: https://github.com/MvvmCross/MvvmCross-Samples/blob/master/TipCalc/TipCalc.WPF/Setup.cs

Related