MvvmCross 5.4 Crash on app startup with NullRef at ConsoleLogProvider
Asked Answered
D

1

6

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

Duffel answered 1/11, 2017 at 8:7 Comment(1)
Can you add an issue in the repo: github.com/MvvmCross/MvvmCross ?Purree
A
24

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;
}
Ament answered 1/11, 2017 at 9:55 Comment(2)
thank you for the quick answer! And workaround which actually works perfectly. Appreciate your helpDuffel
protected override MvxLogProviderType GetDefaultLogProviderType() { return MvxLogProviderType.None; }Ynez

© 2022 - 2024 — McMap. All rights reserved.