Mvvmcross: Null reference exception in type initializer for ConsoleLogProvider on iOS 11 device

Created on 2 Nov 2017  路  2Comments  路  Source: MvvmCross/MvvmCross

Steps to reproduce

  1. Updated application to MvvmCross 5.4.0 and the new IMvxLog and IMvxLogProvider logging system

  2. Tested on iOS simulator without issues

  3. Running on physical iPhone 8, iOS 11.0.3 device throws exception at:

var setup = new Setup(this, Window);
setup.Initialize();

Expected behavior

Should not crash, as I haven't added any custom IMvxLogProvider providers, and done any change (other than injecting IMvxLogProvider and IMvxLog in my classes instead of using Mvx.TaggedTrace). So this could be a problem for more users upgrading from MvvmCross 5.3.

Actual behavior

This is the exception thrown at runtime:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at MvvmCross.Core.Platform.LogProviders.TypeExtensions.GetGetMethod (System.Reflection.PropertyInfo propertyInfo) [0x00000] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider.GetGetConsoleForeground () [0x0000f] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider..cctor () [0x0009e] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at MvvmCross.Core.Platform.MvxSetup.CreateLogProvider () [0x00029] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.MvxSetup.InitializeDebugServices () [0x00012] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.MvxSetup.InitializePrimary () [0x000a0] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.MvxSetup.Initialize () [0x00000] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at Blueye.App.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication application, Foundation.NSDictionary launchOptions) [0x0002f] in /Users/follesoe/Source/BlueyeApp/iOS/AppDelegate.cs:40 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/5481/12e80e01/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5481/12e80e01/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at Blueye.App.iOS.Application.Main (System.String[] args) [0x00001] in /Users/follesoe/Source/BlueyeApp/iOS/Main.cs:17 
2017-11-02 16:52:18.681 Blueye.App.iOS[5554:1805918] Unhandled managed exception:
The type initializer for 'MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider' threw an exception. (System.TypeInitializationException)
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at MvvmCross.Core.Platform.MvxSetup.CreateLogProvider () [0x00029] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.MvxSetup.InitializeDebugServices () [0x00012] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.MvxSetup.InitializePrimary () [0x000a0] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.MvxSetup.Initialize () [0x00000] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at Blueye.App.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication application, Foundation.NSDictionary launchOptions) [0x0002f] in /Users/follesoe/Source/BlueyeApp/iOS/AppDelegate.cs:40 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/5481/12e80e01/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5481/12e80e01/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at Blueye.App.iOS.Application.Main (System.String[] args) [0x00001] in /Users/follesoe/Source/BlueyeApp/iOS/Main.cs:17 
 --- inner exception ---
Object reference not set to an instance of an object (System.NullReferenceException)
  at MvvmCross.Core.Platform.LogProviders.TypeExtensions.GetGetMethod (System.Reflection.PropertyInfo propertyInfo) [0x00000] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider.GetGetConsoleForeground () [0x0000f] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
  at MvvmCross.Core.Platform.LogProviders.ConsoleLogProvider..cctor () [0x0009e] in <68c6fe7539fa471eb0fb4e1ad2630d0d>:0 
2017-11-02 16:52:18.681 Blueye.App.iOS[5554:1805918] critical: Stacktrace:

It looks like the problem is this line: https://github.com/MvvmCross/MvvmCross/blob/00def71adfc391bf0e6b9a477329227409717983/MvvmCross/Core/Core/Platform/LogProviders/ConsoleLogProvider.cs#L96

MethodInfo getForeground = ConsoleType.GetPropertyPortable("ForegroundColor").GetGetMethod();

The GetPropertyPortable returns null, so need check before GetGetMethod call?

Configuration

Version: 5.4.0
Platform:

  • [x] iOS (11.0.3 on iOS 8 device)
  • [ ] Android
  • [ ] WPF
  • [ ] UWP
  • [ ] MacOS
  • [ ] tvOS
  • [ ] Xamarin.Forms
bug

Most helpful comment

All 2 comments

Yes, you can already include this locally in your LinkerPleaseInclude and it will work.

Was this page helpful?
0 / 5 - 0 ratings