0

Our app has been working fine, and now I'm suddenly getting the error below when executing the code private Stack<int> busyStack = new Stack<int>();

It's as if System.Collections.Generic has not been loaded properly.

I'm getting the error here and also in various other places - where we are implicitly creating Lists.

The random nature of this indicates it's a timing issue - that System.Collections.Generic has not been loaded properly when our code is running.

This is on the iOS project in a Xamarin.Forms app, using MvvmCross.

Any thoughts?

This is not a question regarding what a null reference exception is. I know about null references. I have been coding for 30 years. The problem is occurring on the line quoted above, where - sporadically - we're getting the exception below. The question is 'why would one be getting a null reference exception' when creating a System.Collections.Stack?'

Full version information at the bottom of this post.

Error and stack trace:

Object reference not set to an instance of an object (System.NullReferenceException) at System.Collections.Generic.Stack`1[T]..ctor () <0x1a1d124 + 0x0002c> in <2b196ea8d6b243b28c86cc5485ebc43c#91556454b09bd4bc2e66e5853b526f15>:0 at MyProject.Mobile.Common.BusyManager.BusyManager..ctor () [0x00014] in /Users/jameslavery/Documents/GitHub/MyProject.Mobile/MyProject.Mobile.Common/BusyManager/BusyManager.cs:16 at MyProject.Mobile.iOS.Setup.CreateFormsApplication () [0x00043] in /Users/jameslavery/Documents/GitHub/MyProject.Mobile/MyProject.Mobile.iOS/Setup.cs:28 at MvvmCross.Forms.Platforms.Ios.Core.MvxFormsIosSetup.get_FormsApplication () [0x00014] in C:\projects\mvvmcross\MvvmCross.Forms\Platforms\Ios\Core\MvxFormsIosSetup.cs:59 at MvvmCross.Forms.Platforms.Ios.Core.MvxFormsIosSetup.CreateViewPresenter () [0x00000] in C:\projects\mvvmcross\MvvmCross.Forms\Platforms\Ios\Core\MvxFormsIosSetup.cs:80 at MvvmCross.Platforms.Ios.Core.MvxIosSetup.get_Presenter () [0x00000] in C:\projects\mvvmcross\MvvmCross\Platforms\Ios\Core\MvxIosSetup.cs:97 at MvvmCross.Platforms.Ios.Core.MvxIosSetup.RegisterPresenter () [0x00000] in C:\projects\mvvmcross\MvvmCross\Platforms\Ios\Core\MvxIosSetup.cs:109 at MvvmCross.Platforms.Ios.Core.MvxIosSetup.InitializePlatformServices () [0x00006] in C:\projects\mvvmcross\MvvmCross\Platforms\Ios\Core\MvxIosSetup.cs:73 at MvvmCross.Core.MvxSetup.InitializePrimary () [0x00052] in C:\projects\mvvmcross\MvvmCross\Core\MvxSetup.cs:74 at MvvmCross.Core.MvxSetupSingleton.StartSetupInitialization () [0x0000a] in C:\projects\mvvmcross\MvvmCross\Core\MvxSetupSingleton.cs:181 at MvvmCross.Core.MvxSetupSingleton.EnsureInitialized () [0x00017] in C:\projects\mvvmcross\MvvmCross\Core\MvxSetupSingleton.cs:102 at MvvmCross.Forms.Platforms.Ios.Core.MvxFormsApplicationDelegate.FinishedLaunching (UIKit.UIApplication uiApplication, Foundation.NSDictionary launchOptions) [0x00029] in C:\projects\mvvmcross\MvvmCross.Forms\Platforms\Ios\Core\MvxFormsApplicationDelegate.cs:29 at MyProject.Mobile.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00030] in /Users/jameslavery/Documents/GitHub/MyProject.Mobile/MyProject.Mobile.iOS/AppDelegate.cs:44 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 /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/UIKit/UIApplication.cs:79 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/UIKit/UIApplication.cs:63 at MyProject.Mobile.iOS.Application.Main (System.String[] args) [0x00001] in /Users/jameslavery/Documents/GitHub/MyProject.Mobile/MyProject.Mobile.iOS/Main.cs:17

Version Information === Visual Studio Enterprise 2017 for Mac ===

Version 7.7.3 (build 43) Installation UUID: 650b4c91-c7f5-4ee5-ad70-6f178f314906 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

Package version: 516000221

=== Mono Framework MDK ===

Runtime: Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit) Package version: 516000221

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 2.1.5 2.1.2 2.1.1 2.0.5 SDK: /usr/local/share/dotnet/sdk/2.1.403/Sdks SDK Versions: 2.1.403 2.1.302 2.1.301 2.1.4 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.4 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 10.1 (14460.46) Build 10B61

=== Xamarin.Mac ===

Version: 5.2.1.12 (Visual Studio Enterprise) Hash: 65ec520f Branch: Build date: 2018-12-05 12:06:09-0500

=== Xamarin.iOS ===

Version: 12.2.1.12 (Visual Studio Enterprise) Hash: 65ec520f Branch: d15-9 Build date: 2018-12-05 12:06:09-0500

=== Xamarin.Android ===

Version: 9.1.4.2 (Visual Studio Enterprise) Android SDK: /Users/jameslavery/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 2.3 (API level 10) 4.0.3 (API level 15) 4.1 (API level 16) 4.3 (API level 18) 4.4 (API level 19) 5.0 (API level 21) 5.1 (API level 22) 6.0 (API level 23) 7.0 (API level 24) 7.1 (API level 25) 8.0 (API level 26) 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 28.0.0 SDK Build Tools Version: 26.0.2

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/jameslavery/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9 openjdk version "1.8.0-9" OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00) OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 7.7.1.0 Hash: 06ceaea1

=== Xamarin Inspector ===

Version: 1.4.3 Hash: db27525 Branch: 1.4-release Build date: Mon, 09 Jul 2018 21:20:18 GMT Client compatibility: 1

=== Build Information ===

Release ID: 707030043 Git revision: 5896ab2acba037c62271742e9e56b900c96c1d8f Build date: 2019-01-15 21:18:33+00 Build branch: release-7.7 Xamarin extensions: e5b43ba963b7b407aa5b9f2c59018c32a709e6ab

=== Operating System ===

Mac OS X 10.13.6 Darwin 17.7.0 Darwin Kernel Version 17.7.0 Fri Nov 2 20:43:16 PDT 2018 root:xnu-4570.71.17~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

LiveXAML 1.3.31 MFractor 3.7.2 MvvmCross Template pack 2.0.1 NuGet Package Management Extensions 0.14 Template Creator 0.4 Redth's Addins 1.0.9 Internet of Things (IoT) development (Preview) 7.5

G.Mich
  • 1,352
  • 2
  • 20
  • 35
James Lavery
  • 810
  • 4
  • 16
  • It would e awesome if you could provide a [mcve]. – mjwills Jan 21 '19 at 12:37
  • 'now I'm suddenly getting the error below', well, what has changed? Did you tried stepping threw your code via debugger? Good you posted your stacktrace, but without knowing your project setup, its hard to guess where a `List` isn't set. Set a breakpoint the your constructor of `BusyManager` in line 16, then step further and try to find out where your NullRef is thrown. – nilsK Jan 21 '19 at 13:09
  • 1
    @mjwills - I would love to be able to provide a minimal, complete and verifiable example. Unfortunately the error is not consistent enough. – James Lavery Jan 21 '19 at 14:05
  • 1
    @nilsK The NullReference exception is being called on line 16 of our BusyManager class, which is quoted above. The null reference is in calling the Constructor on a _System.Collections.Stack_ It seems to be a timing issue on physical devices, implying that sometimes maybe System.Collections hasn't been loaded correctly. – James Lavery Jan 21 '19 at 14:08
  • 1
    @InBetween - This is not a question regarding what a null reference exception is. It is regarding why calling new Stack() would be causing the exception. We are also getting exceptions raised inside other packages (e.g. MvvmCross) when they are trying to create Lists. Please look at my code I have posted above. – James Lavery Jan 21 '19 at 14:11
  • 2
    I voted for reopening, but I think that you are probably aiming at the wrong direction and that the question will ultimately have to be closed because you haven't provided viable info for answering as probably no one can guess without seeing more of the code. But it is not a duplicate for sure. – Ivan Ičin Jan 21 '19 at 14:26
  • *It's as if `System.Collections.Generic` has not been loaded properly.* That's pretty unlikely, in my experience. Although the stack trace shows the call that provokes the error occurs on line 16 of your code, I suspect the problem is really somewhere else. I would suggest doing a clean and full rebuild of all projects. I think the debug info is incorrect, and reporting the wrong line number. That this "suddenly" started happening and is intermittent indicates that the problem is not with loading `System.Collections.Generic`. – Jim Mischel Jan 21 '19 at 17:36
  • As nothing happened in the meantime, now voting for closing. I agree with @JimMischel that it is nearly impossible that this is the error, but as you are focused on that and don't provide information that would help tracking alternative explanations, this should be closed, IMHO. – Ivan Ičin Jan 22 '19 at 11:13
  • @JimMischel I've done cleans etc. with no resolution. The point I have made several times is that we're also getting this exception at other points in the application - inside package code like MvvmCross's ConsoleLogger - with the same exception when System.Collections.Generic objects are being created. – James Lavery Jan 22 '19 at 15:17
  • 1
    The strange thing is that this now seems to occur on only one physical device. On another iPhone it works fine. I agree let's close. I can't provide repeatable information! – James Lavery Jan 22 '19 at 15:18

0 Answers0