2

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

InfernumDeus
  • 1,185
  • 1
  • 11
  • 33

2 Answers2

3

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.

Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94
  • 2
    It does indeed look like a bug in the library: https://github.com/Fody/Costura/issues/138 From what I understand, when trying to resolve an assembly, it calls `GetName` on the referenced assemblies, which causes the referenced assembly to be loaded. So it goes back into the AssemblyResolve, then call GetName again, then goes back to AssemblyResolve, and so on. – Kevin Gosse Feb 20 '18 at 08:00
  • You are right. I had to change current thread's culture to "en-US" to fix it. – InfernumDeus Feb 20 '18 at 08:47
2

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;
Programmierus
  • 167
  • 11