Bug 2440 - System.UnauthorizedAccessException with fast deployment to emulator
Summary: System.UnauthorizedAccessException with fast deployment to emulator
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Android Add-in ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2011-12-09 11:56 UTC by Jonathan Pryor
Modified: 2016-08-03 15:37 UTC (History)
4 users (show)

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:

Description Jonathan Pryor 2011-12-09 11:56:39 UTC
To reproduce:

 1. Fire up an emulator (tested on API levels 8 & 10; not sure about others)
 2. Create a new Project within MonoDevelop/VS
 3. Edit OnCreate() and add the following code:

	string dbPath = Path.Combine(

	if (File.Exists(dbPath)) {
	else {
		File.WriteAllText(dbPath, "Blabla");

 3. Build project as Debug
 4. Ensure that Fast Deployment is enabled.
 5. Run the app
 6. App dies:

I/MonoDroid(  374): UNHANDLED EXCEPTION: System.UnauthorizedAccessException: Access to the path "/data/data/Mono.Samples.HelloTests/files/items.db3" is denied.
I/MonoDroid(  374): at System.IO.FileStream..ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,bool,System.IO.FileOptions) <0x006e8>
I/MonoDroid(  374): at System.IO.FileStream..ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int) <0x0005f>
I/MonoDroid(  374): at System.IO.File.Create (string,int) <0x00047>
I/MonoDroid(  374): at System.IO.File.Create (string) <0x00017>

(Alternate repro: Run https://github.com/xamarin/monodroid-samples/tree/master/SanityTests on the emulator)

Why does it fail?

# ls -l /data/data/Mono.Samples.HelloTests
drwxrwx--x app_42   app_42            2011-12-09 11:08 cache
drwxrwxrwx root     root              2011-12-09 11:09 files
drwxr-xr-x system   system            2011-12-09 10:53 lib

$HOME is (1) owned by root, and (2) 775. Result: the user can't write to $HOME!

This is _probably_ because adb is running as root on the device, so when we create $HOME/files/... for fast deployment, they're created as the root user with default permissions (775).

A (probably sane?) fix would be to chmod the directory to 777 after file sync. (Manually changing $HOME permissions to 777 allows the app to start.)

Workaround: disable fast deployment.
Comment 1 Andreia Gaita 2011-12-12 11:38:32 UTC
permissions on SanityTests app on

2.3 emulator:

adb shell ls -l /data/data/Mono.Samples.SanityTests
drwxrwxr-x root     root              2011-12-12 16:30 files
drwxr-xr-x system   system            2011-12-12 16:30 lib

4.0 emulator:

adb shell ls -l /data/data/Mono.Samples.SanityTests
drwxrwxrwx root     root              2011-12-12 16:36 files
drwxr-xr-x system   system            2011-12-12 16:36 lib

So, yay.... /me facepalms
Comment 2 Andreia Gaita 2012-01-09 07:03:41 UTC
Fixed in 12fecb047d0, included in MfA 4.0.2