So I am trying to lock an isolated storage file in my C# client application, so that multiple copies of my application are not able to access it at the same time. I am using the following syntax:
lockStream = new IsolatedStorageFileStream("my.lck", FileMode.OpenOrCreate, isoStore);
lockStream.Lock(0, 0);
This code causes my application to throw a NullReferenceException from inside the FileStream.Lock method of the framework. I have tried using a non-zero value for the length. I have tried writing a byte to the file and then locking just that byte. No matter what I do, that same NullReferenceException keeps plaguing me. Does anyone know if this is possible with isolated storage?
Also I am looking into using this technique in a Silverlight application as well, does Silverlight support file locking? The MSDN docs seem to indicate that it does not, but I have seen this post from a C# MVP that says it does.
Update: Microsoft has fixed the bug I submitted on Connect, but it was not released in version 4 of the framework. It should be available hopefully in the next SP or full release.