'MvxWpfSetup<App>' must be a non-abstract type with a public parameterless constructor
Asked Answered
T

3

5

I'm trying to follow the code at the end of this video here, but I'm getting this error around the 1:11:10 mark:

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[])'

I really have no idea what code is relevant, but this is the file thats giving the error:

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<MvxStarter.Core.App>>();
        }
    }
}

I went over this whole section multiple times and I'm pretty certain I have exactly what he has. I even downloaded his source code, but I couldnt open the project so I copied and pasted all the code and I'm still getting this error. What should I do? I can post more relevant code if you tell me what to post. I have no idea what this error means and nothing I can find online about it makes any sense.

edit: I tried following the official documentation example project and I got the exact same error on the exact same line. Is something wrong with my installation? https://www.mvvmcross.com/documentation/tutorials/tipcalc/the-core-project https://www.mvvmcross.com/documentation/tutorials/tipcalc/a-wpf-ui-project

Tullus answered 14/6, 2021 at 5:56 Comment(0)
P
6

Need to create Setup class so code becomes. 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<Setup>();
        }
    }
}

Then Setup becomes

namespace MvxStarter.Wpf
{
    public class Setup : MvxWpfSetup<Core.App>
    {
        protected override ILoggerProvider CreateLogProvider()
        {
            return new SerilogLoggerProvider();
        }

        protected override ILoggerFactory CreateLogFactory()
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .CreateLogger();

            return new SerilogLoggerFactory();
        }
    }
}

or similar. This used Nuget Serilog as well as others.

Pepsinate answered 17/6, 2021 at 23:13 Comment(3)
When I try this code I get the error The non-generic type 'MvxWpfSetup' cannot be used with type argumentsBurks
Does the WPF project include your .Core project? Core.app references your XX.Core application which in this case would be MvxStarter.Core. This project should contain an App.cs which inherits from MvvmCross.ViewModels.MvxApplication.Pepsinate
Thank you, @ivie, but I did somehow manage to get everything to do with the Setup class working. I don't recall exactly what I did though.Burks
R
4

I was running in to the same problem and found out it is due to breaking changes between MvvmCross 7 and MvvmCross8. In the video of Tim Corey version 7 is used.

Here is a link to the upgrade page: https://www.mvvmcross.com/documentation/upgrading/upgrade-to-mvvmcross-80

Rheumatism answered 15/6, 2021 at 18:59 Comment(0)
T
0

I want to add to ivie's answer that when using mvvmcross 8, you also need to add the attributes

[MvxContentPresentation]
[MvxViewFor(typeof(*YOURCLASSNAME*ViewModel))]

on top of the partial class in your corresponding view.

As shown on the TipsCalc example class on github https://github.com/MvvmCross/MvvmCross-Samples/blob/master/TipCalc/TipCalc.WPF/Views/TipView.xaml.cs

Trophy answered 17/9, 2021 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.