c# - 如何处理xamarin.forms中app.xaml.cs中的System.TypeLoadException?

标签 c# xamarin xamarin.forms

很抱歉打扰您,但我在代码中遇到了一个错误,但我不知道如何处理。

每当我尝试运行我的应用程序时,我都会遇到以下问题:

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

它指出它发生在InitializeComponent();时。在App.xaml.cs的构造函数中调用。

有问题的构造函数:

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

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

应用程序.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;

            }

        }

    }
}

感谢您的阅读,任何提示/帮助都将对编写不恰当的代码有很大帮助。

最佳答案

请问可以吗

  • 确保您的解决方案中没有相同 Nuget 的不同版本。

  • 清理并重建您的项目

如果这对您不起作用,请尝试删除所有 obj 和 bin 文件夹并重建。

这通常是由于更新或版本冲突而发生的,至少在我的情况下是这样。

您介意向我们展示 LoginFinal 方法吗?

我想你可以直接调用Login

  MainPage = new NavigationPage(new Login);

关于c# - 如何处理xamarin.forms中app.xaml.cs中的System.TypeLoadException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59983341/

相关文章:

c# - 更改 WPF 窗口的内容

c# - Xamarin - 将命令绑定(bind)到用户控件内对象的属性

c# - `Failed resolution of: Lcom/google/android/datatransport/TransportFactory` 使用 Xamarin.Firebase 时

android - 生成错误 : Invalid resource directory name: "res renderers"

c# - 如何在 Xamarin.Forms.Map 中获取当前位置或移动到当前位置

c# - MemoryStream - 无法访问已关闭的流

c# - 如何从 Xamarin.Forms 中的 NavigationStack 中删除模式页面

c# - 将 swagger-ui 输出保存到文件

c# - Cocoa(Xamarin.Mac)应用程序是否支持System.Drawing.Graphics

sqlite - Xamarin Android - 在哪里存储本地数据库以便我可以查看它