NullReferenceException during bootup of brand-new Android project (Visual Studio 2017)

I’m using the MonoGame Android Project template in Visual Studio 2017 (installed MonoGame 3.6). I have made no changes to the project or to the startup code. Downloaded API 25 using Android SDK Manager.

Running the application through “BlackBerry BBB100-1 (Android 7.1 - API 25)” produces the following bits of output (they seemed the most relevant):

08-13 12:00:12.983 D/MonoGame(26266): MonoGameAndroidGameView Context Set 08-13 12:00:12.987 D/MonoGame(26266): Created format Index: 2099330, Color: 32 (8888), Depth: 24, Stencil: 8, Samples: 0, Accum: 32 (8888), Buffers: 0, Stereo: False 08-13 12:00:12.988 D/Mono (26266): DllImport attempting to load: 'libGLESv2.dll'. 08-13 12:00:12.988 D/Mono (26266): DllImport error loading library './libGLESv2.dll': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/./libGLESv2.dll" not found'. 08-13 12:00:12.989 D/Mono (26266): DllImport error loading library './libGLESv2.dll.so': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/libaot-libGLESv2.dll.so" not found'. 08-13 12:00:12.990 D/Mono (26266): DllImport error loading library '/system/lib/libGLESv2.dll': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm//system/lib/libGLESv2.dll" not found'. 08-13 12:00:12.990 D/Mono (26266): DllImport error loading library '/system/lib/libGLESv2.dll.so': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/libaot-libGLESv2.dll.so" not found'. 08-13 12:00:12.991 D/Mono (26266): DllImport error loading library 'libGLESv2.dll': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/libGLESv2.dll" not found'. 08-13 12:00:12.992 D/Mono (26266): DllImport error loading library 'libGLESv2.dll.so': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/libaot-libGLESv2.dll.so" not found'. 08-13 12:00:12.993 D/Mono (26266): DllImport error loading library 'libGLESv2.dll': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/libGLESv2.dll" not found'. 08-13 12:00:12.993 D/Mono (26266): DllImport error loading library './libGLESv2': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/./libGLESv2" not found'. 08-13 12:00:12.993 D/Mono (26266): DllImport error loading library './libGLESv2.so': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm/./libGLESv2.so" not found'. 08-13 12:00:12.994 D/Mono (26266): DllImport error loading library '/system/lib/libGLESv2': 'dlopen failed: library "/data/app/Game2.Game2-1/lib/arm//system/lib/libGLESv2" not found'. 08-13 12:00:12.994 D/Mono (26266): DllImport loaded library '/system/lib/libGLESv2.so'. 08-13 12:00:12.994 D/Mono (26266): DllImport searching in: 'libGLESv2.dll' ('/system/lib/libGLESv2.so'). 08-13 12:00:12.994 D/Mono (26266): Searching for 'glCheckFramebufferStatus'. 08-13 12:00:12.999 D/MonoGame(26266): Framebuffer Status: FramebufferComplete 08-13 12:00:13.004 D/MonoGame(26266): MonoGameAndroidGameView.SurfaceCreated: surfaceFrame = Rect(0, 0 - 1080, 1620)

08-13 12:00:16.901 I/MonoDroid(26266): UNHANDLED EXCEPTION: 08-13 12:00:16.957 I/MonoDroid(26266): System.NullReferenceException: Object reference not set to an instance of an object. 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformInitialize () [0x0002d] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Initialize () [0x00000] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.Graphics.GraphicsDevice..ctor (Microsoft.Xna.Framework.Graphics.GraphicsAdapter adapter, Microsoft.Xna.Framework.Graphics.GraphicsProfile graphicsProfile, Microsoft.Xna.Framework.Graphics.PresentationParameters presentationParameters) [0x00165] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.GraphicsDeviceManager.Initialize () [0x0007a] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.GraphicsDeviceManager.CreateDevice () [0x00000] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.Game.DoInitialize () [0x00016] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.AndroidGamePlatform.BeforeUpdate (Microsoft.Xna.Framework.GameTime gameTime) [0x0000e] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.Game.DoUpdate (Microsoft.Xna.Framework.GameTime gameTime) [0x00006] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.Game.Tick () [0x000ee] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Microsoft.Xna.Framework.AndroidGameWindow.OnUpdateFrame (System.Object sender, OpenTK.FrameEventArgs frameEventArgs) [0x00053] in <1fc1543e5ebd4c96aeb92ea52a0d70e5>:0 08-13 12:00:16.957 I/MonoDroid(26266): at OpenTK.GameViewBase.OnUpdateFrame (OpenTK.FrameEventArgs e) [0x00008] in <e96a295c47bf446180d3e093f1bb1f17>:0 08-13 12:00:16.957 I/MonoDroid(26266): at OpenTK.Platform.Android.AndroidGameView.UpdateFrameInternal (OpenTK.FrameEventArgs e) [0x00009] in <e96a295c47bf446180d3e093f1bb1f17>:0 08-13 12:00:16.957 I/MonoDroid(26266): at OpenTK.Platform.Android.AndroidGameView.RunIteration (System.Threading.CancellationToken token) [0x00073] in <e96a295c47bf446180d3e093f1bb1f17>:0 08-13 12:00:16.957 I/MonoDroid(26266): at OpenTK.Platform.Android.AndroidGameView+<>c__DisplayClass59_0.<StartThread>b__1 (System.Object _) [0x00000] in <e96a295c47bf446180d3e093f1bb1f17>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Android.App.SyncContext+<>c__DisplayClass3_0.<Send>b__0 () [0x00000] in <d855bac285f44dda8a0d8510b679b1e2>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0 08-13 12:00:16.957 I/MonoDroid(26266): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0 08-13 12:00:16.957 I/MonoDroid(26266): at (wrapper dynamic-method) System.Object:fc7165fd-00fd-47ed-b7fb-aecb3dea7b8b (intptr,intptr)

Any and all help is appreciated. Let me know if more information is required. Thanks.

Just to add, the GraphicsDevice instance within the GraphicsDeviceManager is null after the Game1 constructor has finished executing, so I’m guessing (based off the MonoGame source code) that will explain the NullReferenceException I posted the stack trace for above.

Thanks for reporting this. This bug was just introduced a couple days ago. Unfortunately we don’t run automated tests for Android yet, so this issue wasn’t detected. It’s an easy fix, so will be resolved quickly. You can temporarily use the 3.6 release if you want a workaround.

Downloaded the 6.3 release for Visual Studio from that link, created a new project, deployed to the phone. I get the blue screen as expected. Thanks!

1 Like

PR #5877 has been submitted to fix this.

1 Like