MvvmCross 5.4在ConsoleLogProvider上使用NullRef启动应用时崩溃 [英] MvvmCross 5.4 Crash on app startup with NullRef at ConsoleLogProvider

查看:86
本文介绍了MvvmCross 5.4在ConsoleLogProvider上使用NullRef启动应用时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将Xamarin.Android应用程序包MvvmCross5.3.2更新到了5.4,并且应用程序在启动时开始崩溃.我手动确定原因是链接器-我启用了link SDK libs only选项.使用None选项,它可以很好地工作,但包装要大一倍.

I've updated my Xamarin.Android app package MvvmCross from 5.3.2 to 5.4 and app start crashing on startup. Manually I identified that the reason is the linker - I have link SDK libs only option enabled. With the None option it works just fine but makes a twice bigger package.

"MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider"的类型初始值设定项引发了异常. ---> System.NullReferenceException:对象引用未设置为对象的实例

The type initializer for 'MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object

推荐答案

这是MvvmCross 5.4中的一个已知错误,将在下一版本中修复.

This is a known bug in MvvmCross 5.4 and will be fixed in the next version.

同时,作为一种变通办法,您可以转到您的Setup类并覆盖GetDefaultLogProviderType,以便它返回MvxLogProviderType.None,如下所示:

In the meantime, as a work around, you can go to your Setup class and override GetDefaultLogProviderType so it returns MvxLogProviderType.None, like this:

protected override MvxLogProviderType GetDefaultLogProviderType() 
    => MvxLogProviderType.None;

编辑

由于提供程序依赖于反射,因此如果要将控制台提供程序与IMvxLog一起使用,只需在LinkerPleaseInclude.cs中将其包括在内:

Since the providers rely on reflection, if you wanna use the Console provider with IMvxLog, simply include this in your LinkerPleaseInclude.cs:

using System;

//[...]

public void Include(ConsoleColor color)
{
    Console.Write("");
    Console.WriteLine("");
    color = Console.ForegroundColor;
    Console.ForegroundColor = ConsoleColor.Red;
    Console.ForegroundColor = ConsoleColor.Yellow;
    Console.ForegroundColor = ConsoleColor.Magenta;
    Console.ForegroundColor = ConsoleColor.White;
    Console.ForegroundColor = ConsoleColor.Gray;
    Console.ForegroundColor = ConsoleColor.DarkGray;
}

这篇关于MvvmCross 5.4在ConsoleLogProvider上使用NullRef启动应用时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆