Bug 58854 - Values from NSUserDefaults are null in Sandbox Mode
Summary: Values from NSUserDefaults are null in Sandbox Mode
Status: RESOLVED INVALID
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-08-17 16:23 UTC by Marko
Modified: 2017-08-30 17:04 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 INVALID

Description Marko 2017-08-17 16:23:16 UTC
When you try to read a value from NSUserDefaults, the value is null (in Sandbox Mode). This has worked before, but stopped working with the current release. Here's some code:

var defaults = Foundation.NSUserDefaults.StandardUserDefaults;
defaults.SetString("test", "test");
var test = defaults.StringForKey("test");

The variable test is always null, but it should contain "test". This works only as expected when you disable Sandbox Mode.
Comment 1 Sebastien Pouliot 2017-08-18 20:26:28 UTC
Xamarin.Mac does not do anything different between running unrestricted or in a sandbox.

However there are common issues that could explain this, e.g. https://stackoverflow.com/q/22242106/220643

> This has worked before, but stopped working with the current release. 

Can you provide more information, like the XM version you were using ?
Comment 2 Chris Hamons 2017-08-18 20:34:13 UTC
A small project showing the exact code you are using, sandbox configuration, and such would also be useful.

As @Sebastien correctly noted, in this case Xamarin.Mac is a rather thin layer above the APIs in question.
Comment 3 Marko 2017-08-29 23:44:54 UTC
This was probably a problem with running the app with debug and store provision profiles. After deleting ~/Library/Containers/"Bundle Identifier", everything worked again. 

Sorry for the inconvenience
Comment 4 Sebastien Pouliot 2017-08-30 17:04:49 UTC
@Marko, thanks for updating us on the status. We're glad things are working again :)