简体   繁体   中英

How to deal with System.TypeLoadException in the app.xaml.cs in xamarin.forms?

Sorry to bother you, but I've come across a error in my code I don't how to deal with.

Whenever I try to run my app, I get faced with this:

System.TypeLoadException: 'Could not resolve type with token 01000019 from typeref (expected class 'Xamarin.Forms.Xaml.Diagnostics.VisualDiagnostics' in assembly 'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null')'

It states it occurs when the InitializeComponent(); is called in the constructor of App.xaml.cs.

Constructor in question:

public App()
    {
        //Line throwing the error
        InitializeComponent();

        MainPage = new NavigationPage(new Login.LogonFinal()); //Defines what page the app opens on when starting
    }

App.xaml.cs

using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace NEA_I_MDL
{
    public partial class App : Application
    {

        static Databases.AccountDatabaseController AccountDatabaseVar;

        public App()
        {
            //Line throwing the error
            InitializeComponent();

            MainPage = new NavigationPage(new Login.LogonFinal()); //Defines what page the app opens on when starting
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }

        public static Databases.AccountDatabaseController AccountDatabaseFunc
        {

            get
            {

                if(AccountDatabaseVar == null)
                {
                    AccountDatabaseVar = new Databases.AccountDatabaseController();
                }

                return AccountDatabaseVar;

            }

        }

    }
}

Thank you for reading, any tips/assistance will be a huge help for ineptly written code.

Can I ask that you please

  • Make sure you dont have different versions of the same Nugets in your solution.

  • Clean & Rebuild your Project

If That doesn't work for you try delete all your obj and bin folders and rebuild.

This usually happens because of Updates or version conflicts In my case atleast.

And do you mind showing us the LoginFinal Method?

I think you can just call Login

  MainPage = new NavigationPage(new Login);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM