Bug 11771 - IsolatedStorageFile.GetFileNames() throws exception w/ nested dirs
Summary: IsolatedStorageFile.GetFileNames() throws exception w/ nested dirs
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rodrigo Kumpera
Depends on:
Reported: 2013-04-13 17:05 UTC by Jonathan Pryor
Modified: 2018-03-16 03:14 UTC (History)
6 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 GitHub or Developer Community 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 2013-04-13 17:05:40 UTC
Context: http://forums.xamarin.com/discussion/3092/system-security-securityexception

(Yes, a Xamarin.Android bug, but it applies to desktop mono.)

Consider the following app:

  // IsolatedStorage DeleteDirectory
  using System;
  using System.IO;
  using System.IO.IsolatedStorage;
  class Test {
    public static void Main ()
      string dir = Path.Combine("Dir", "Level");
      using (var f = IsolatedStorageFile.GetUserStoreForAssembly ())
        f.CreateDirectory (dir);
        using (var o = f.CreateFile(Path.Combine(dir, "o2")))
          o.Write(new byte[] { 1, 2, 3 }, 0, 3);
      DeleteDirectory (dir);
    public static void DeleteDirectory(string directory)
      using (var store = IsolatedStorageFile.GetUserStoreForAssembly ())
        if (store.DirectoryExists(directory))
          // System.Security.SecurityException HERE!
          var files = store.GetFileNames(Path.Combine(directory, "*"));
          foreach (string file in files)
            store.DeleteFile(Path.Combine(directory, file));

Run it, and it dies with a SecurityException:

> $ dmcs -debug+ iso-del.cs && mono --debug iso-del.exe 
> Unhandled Exception:
> System.Security.SecurityException: A security error has been detected.
>   at System.IO.IsolatedStorage.IsolatedStorageFile.GetFileNames (System.String searchPattern) [0x000ba] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-3.0.7/_build/mono-3.0.7.git/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs:850 
>   at (wrapper remoting-invoke-with-check) System.IO.IsolatedStorage.IsolatedStorageFile:GetFileNames (string)
>   at Test.DeleteDirectory (System.String directory) [0x00015] in /Users/jon/tmp/csharp/iso-del.cs:27 
>   at Test.Main () [0x0006f] in /Users/jon/tmp/csharp/iso-del.cs:17 

Here's the "funny" thing; it's caused by nested directories. Change line 9 to:

      string dir = "Dir";

and it works without exception.

(Note: to "work without exception" it needs to be a _clean_ isolated storage environment. Thus, if you run the "buggy" version you'll need to nuke ~/.config/.isolated-storage/*; after nuking, the "fixed" app will work w/o error.)

No SecurityException should be generated for nested directories.
Comment 1 Jordan Earls 2013-08-23 10:46:33 UTC
This bug is actually not a bug depending on how you look at it. This is the commit responsible for it: https://github.com/mono/mono/commit/b79a9d584792d4b74c8269acecab6d7eef526015

It would appear that the Mono team was following Windows Phone 7 development at the time and when it came out, it had this huge breaking change/bug in it's IsolatedStorage implementation(from what I can tell in my own legacy code to workaround it). So, Mono decided to follow and implement all APIs to the do the same as Windows Phone. This was fixed in subsequent versions of Windows Phone and Silverlight. This code appears to have almost sneaked in even. There was no bug report or anything for this "fix" in Mono. I have a feeling that if there were, it would've been spotted and thrown out as "we don't want to copy Microsoft's bug".. So, I suggest reverting the relevant portion of that commit
Comment 2 Kent Green [MSFT] 2015-02-26 14:26:31 UTC
Customer from this desk case https://xamarin.desk.com/agent/case/127553, reports hitting this issue. 

The exception is thrown if they call the IsolatedStorageFile.GetFileNames with nested directories. It works only on first level directory. As it stands they can't delete any files created in nested directories without knowing the exact names.

They also asked what the status of this bug is & if there are any known workarounds.
Comment 3 Melbourne Developer 2017-03-20 05:12:13 UTC
I'm getting this problem as well!

I'm getting it on Android. I am trying to iterate through files in a nested folder. But I get the error "A security error has been detected"

Please fix this bug!
Comment 4 Melbourne Developer 2017-03-21 05:01:56 UTC
When will this be fixed?
Comment 5 Melbourne Developer 2017-04-05 00:19:56 UTC
Please fix this bug.
Comment 6 Melbourne Developer 2017-06-01 02:02:47 UTC
Has this been fixed?
Comment 7 Melbourne Developer 2018-03-14 01:46:09 UTC
I got an email about this but I can't see any new comments. Is this bug now going to be fixed?
Comment 8 Marek Safar 2018-03-14 12:05:08 UTC
It was status change notification email
Comment 9 Melbourne Developer 2018-03-14 22:17:57 UTC
So it's being fixed? That's great.
Comment 10 Rodrigo Kumpera 2018-03-14 22:29:24 UTC
Proposed fix: https://github.com/mono/mono/pull/7618

Hey Melbourne, is this bug still relevant to you? We'll backport it to the next available release if that would help you.
Comment 11 Marek Safar 2018-03-15 08:07:33 UTC
Fixed in master and Mono 5.12
Comment 12 Melbourne Developer 2018-03-16 03:14:08 UTC
Thankyou very much. No that's not necessary. We can wait for the next release. How do we know when mono is upgraded as a part of Xamarin on the various platforms?