IsolatedStorageFileStream lead to assert failure

887 Views Asked by At

I decided to use isolated storage for temporary files:

using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForDomain())
{
    using (IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Create, isoStore))
    {

    }
}

I taken this code from example that works on this computer. And minimal project with just this code also sucessfully runs.

But while performing IsolatedStorageFileStream constructor in my current project following message appears:

MyApp.exe - Assert Failure

Expression: [mscorlib recursive resource lookup bug]

Desctiprion: Infinite recurion during resource lookup within mscorlib. This may be a bug in mscorlib, or potentially in certain extensibility points such as assembly resolve events or CultureInfo names.

Resource name: Serurity_Generic

And in this message I can see pretty big stack trace (it starts with call of IsolatedStorageFileStream constructor):

enter image description here

Also I can't catch exception from this code.

Looks like error happened in System.Environment.ResourceHelper.GetResourceStringCode().

What can be a possible reason for this? I can't find anything on this topic.

Deleting C:\Users\user\AppData\Local\IsolatedStorage folder doesn't solve the problem (I know for sure that there is only my folders).

2

There are 2 best solutions below

2
Kevin Gosse On BEST ANSWER

Looking at the stacktrace, the base issue comes from LongPathFile.GetLength. There could be some invalid characters in the path, or maybe a permission issue. Hard to tell without the exact error code. Then, .NET tries to load the error message related to the error code, and at some point steps into Costura.AssemblyLoader (this must be your code or some library you're referencing). It looks like that AssemblyLoader subscribed to the AssemblyResolve event, and is doing a poor job fetching the correct assembly because it actually causes an infinite recursion.

In a nutshell: fix that assembly loader, then you'll be able to get the real error.

0
Programmierus On

In my case exactly this happened on some of the machines when my code tried to create a new file in IsolatedStorage. As correctly mentioned in InfernumDeus's comment it happens only when the machine has non-English active locale set. Following code fixed the issue in my case:

var currentCulture = Thread.CurrentThread.CurrentCulture;
var currentUiCulture = Thread.CurrentThread.CurrentUICulture;

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

var traceFileStream = new IsolatedStorageFileStream("system_log.txt", FileMode.OpenOrCreate, FileAccess.Write);

Thread.CurrentThread.CurrentCulture = currentCulture;
Thread.CurrentThread.CurrentUICulture = currentUiCulture;