It looks like a bug in the Framework. Maybe I'm wrong because it is really too big to be true.
Looking at the source code for .NET 3.5 SP1 with Reflector, you will find that IsolStorageFileStream calls the dimensionless base constructor (FileStream ()), which leads to a non-initialized base class. IsolatedStorageFileStream creates an instance of FileStream and uses it in all methods that it overrides (Write, Read, Flush, Seek, etc.). It is strange that it does not directly use its base class.
But the lock and unlock are not overridden, and they need a private field (_handle), which is still null (since the constructor used is parameterless). They assume that it is non-zero and casts it and calls NRE.
To summarize, locking and unlocking are not supported (or do not work).
I think you are forced to use other locking methods, such as Mutex or Semaphore.
The implementation is the same in .NET 4 RC. In Silverlight, there is no unlock lock at all (my apologies for the conflict with MVP).
source share