Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

mvvmcross

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

like image 738
cinderofsouls Avatar asked Mar 02 '23 13:03

cinderofsouls


2 Answers

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.

like image 182
ivie Avatar answered Mar 05 '23 12:03

ivie


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

like image 39
birdy1980 Avatar answered Mar 05 '23 13:03

birdy1980