MvvmCross 5.4 Crash on app startup with NullRef at ConsoleLogProvider

…衆ロ難τιáo~ 提交于 2020-01-02 04:16:12

问题


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.

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


回答1:


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

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;

EDIT

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;
}


来源:https://stackoverflow.com/questions/47050608/mvvmcross-5-4-crash-on-app-startup-with-nullref-at-consolelogprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!