Bug 35304 - [tvos] ArgumentNullException calling NSUserDefaults.StandardUserDefaults from Library
Summary: [tvos] ArgumentNullException calling NSUserDefaults.StandardUserDefaults from...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.TVOS.dll ()
Version: XI 9.3 (xcode 7.1 previews)
Hardware: Macintosh Mac OS
: --- enhancement
Target Milestone: (C7)
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
: 35638 ()
Depends on:
Blocks:
 
Reported: 2015-10-27 14:18 UTC by Vincent Roggero
Modified: 2016-01-22 15:57 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Vincent Roggero 2015-10-27 14:18:06 UTC
NSUserDefaults nsUD = NSUserDefaults.StandardUserDefaults;

System.ArgumentNullException: Value cannot be null.
Parameter name: obj
  at at (wrapper managed-to-native) System.Threading.Monitor:enter_with_atomic_var (object,bool&)
  at System.Threading.Monitor.Enter (System.Object obj, System.Boolean& lockTaken) [0x00000] in /Users/builder/data/lanes/2128/155d35b9/source/watch/mono/mcs/class/corlib/System.Threading/Monitor.cs:202
  at ObjCRuntime.Runtime.TryGetNSObject (IntPtr ptr, Boolean evenInFinalizerQueue) [0x00000] in /Users/builder/data/lanes/2128/155d35b9/source/maccore/src/ObjCRuntime/Runtime.cs:842
  at ObjCRuntime.Runtime.TryGetNSObject (IntPtr ptr) [0x00000] in /Users/builder/data/lanes/2128/155d35b9/source/maccore/src/ObjCRuntime/Runtime.cs:837
  at ObjCRuntime.Runtime.GetNSObject[T] (IntPtr ptr) [0x00017] in /Users/builder/data/lanes/2128/155d35b9/source/maccore/src/ObjCRuntime/Runtime.cs:877
  at Foundation.NSUserDefaults.get_StandardUserDefaults () [0x00000] in /Users/builder/data/lanes/2128/155d35b9/source/maccore/src/build/ios/native/Foundation/NSUserDefaults.g.cs:662
  at ToolsMT.LangUtil.get_CurrentLanguageCodeFull () [0x00001] in /Users/vincentr/GitHub/Tools/ToolsMT/Utils.cs:1746
  at ToolsMT.LangUtil.get_CurrentLanguageCode () [0x00001] in /Users/vincentr/GitHub/Tools/ToolsMT/Utils.cs:1735
  at ToolsMT.Extension.localize (System.String key) [0x0000d] in /Users/vincentr/GitHub/Tools/ToolsMT/Utils.cs:1976
  at ToolsMT.LangUtil.Localize (System.String key) [0x00002] in /Users/vincentr/GitHub/Tools/ToolsMT/Utils.cs:1875
  at ToolsMT.MessageBox.Show (System.String messageBoxText, System.String caption, MessageBoxButton buttonType) [0x00025] in /Users/vincentr/GitHub/Tools/ToolsMT/MessageBox.cs:40
  at ToolsMT.MessageBox.Show (System.String messageBoxText) [0x00008] in /Users/vincentr/GitHub/Tools/ToolsMT/MessageBox.cs:188
  at THXTuneup.HomeViewController.btnGetStarted (Foundation.NSObject sender) [0x00006] in /Users/vincentr/GitHub/THX-tune-up/tvOS/THXTune-up/THXTune-up/HomeViewController.cs:33
  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2128/155d35b9/source/maccore/src/UIKit/UIApplication.cs:74
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2128/155d35b9/source/maccore/src/UIKit/UIApplication.cs:58
  at THXTuneup.Application.Main (System.String[] args) [0x00008] in /Users/vincentr/GitHub/THX-tune-up/tvOS/THXTune-up/THXTune-up/Main.cs:12

****Note: XS intellisense and Immediate window will resolve properly;
> NSUserDefaults.StandardUserDefaults
{<NSUserDefaults: 0x7fce89e127b0>}
	Class: {ObjCRuntime.Class}
	ClassHandle (Foundation.NSUserDefaults): 0x10b820f30
	ClassHandle (Foundation.NSObject): 0x10b820f30
	DebugDescription: "<NSUserDefaults: 0x7fce89e127b0>"
	Description: "<NSUserDefaults: 0x7fce89e127b0>"
	Handle: 0x7fce89e127b0
	IsProxy: false
	RetainCount: 7
	Self: {<NSUserDefaults: 0x7fce89e127b0>}
	SuperHandle: 0x11a1fdbf8
	Superclass: {ObjCRuntime.Class}
	Zone: {Foundation.NSZone}
	Static members: 
	Non-public members:
Comment 1 Vincent Roggero 2015-10-27 14:27:17 UTC
=== Xamarin Studio ===

Version 5.10 (build 913)
Installation UUID: 5df374dd-127a-4b3e-bfa6-0a872d52b886
Runtime:
	Mono 4.0.4 ((detached/d481017)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400040004

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.Mac ===

Version: 2.0.2.111 (Starter Edition)

=== Xamarin.iOS ===

Version: 9.3.0.243 (Business Edition)
Hash: 155d35b
Branch: master
Build date: 2015-09-30 18:26:52-0400

=== Xamarin.Android ===

Version: 5.1.7.12 (Business Edition)
Android SDK: /Users/vincentr/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)

SDK Tools Version: 24.1.2
SDK Platform Tools Version: 22.0.0
SDK Build Tools Version: 22.0.1

Java SDK: /usr
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Build Information ===

Release ID: 510000913
Git revision: d437b9453df0bd08103df76b60a2bb95c3a864a6
Build date: 2015-09-30 16:56:55-04
Xamarin addins: 2c839fd62864efbeb8d02091e4ba3dfde24a099a
Build lane: monodevelop-lion-xcode7.1

=== Operating System ===

Mac OS X 10.10.5
Darwin Vincents-iMac.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 2 Sebastien Pouliot 2015-11-09 21:03:10 UTC
This sounds very similar to but #35638.

Unit tests works fine for that call and the location of the stack trace (Monitor.cs) looks incorrect. Can you provide us with a test case that can reproduce this issue, even if a bit randomly ? Thanks
Comment 3 Sebastien Pouliot 2015-12-01 13:44:07 UTC
Were you able to track down why this happened ? or how you solved it ?
Comment 4 Vincent Roggero 2015-12-01 15:23:56 UTC
I believe the issue was due to my library using Xamarin.iOS.
To resolve this issue I've created a tvOS library, linked the source files from the iOS library, and added #if compiler directives when building for iOS vs tvOS.
Comment 5 Sebastien Pouliot 2016-01-11 17:49:07 UTC
*** Bug 35638 has been marked as a duplicate of this bug. ***
Comment 6 Sebastien Pouliot 2016-01-11 17:51:00 UTC
@Rolf, wrt comment #4 can you check that we do not allow two platform assemblies being referenced. I'm sure we had that for monotouch.dll/Xamarin.iOS.dll but maybe not for the new tv/watch platforms.
Comment 7 Rolf Bjarne Kvinge [MSFT] 2016-01-22 15:57:14 UTC
Fixed mtouch to detect (and show an error) any incorrect platform assembly, not just monotouch.dll vs Xamarin.iOS.dll

maccore/master: 76aa5761ac84b3587fcfea91690ffd87cdfd1013