Search code examples
c#windows-7isolatedstoragefile

IsolatedStorageFileStream lead to assert failure


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).


Solution

  • 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.