Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 654755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:31:44+00:00 2026-05-13T22:31:44+00:00

So I am trying to lock an isolated storage file in my C# client

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:31:44+00:00Added an answer on May 13, 2026 at 10:31 pm

    This looks like a bug in the Framework. I may be wrong, because it is really too big to be true.

    Looking at the source code of .NET 3.5 SP1 with Reflector, one finds the IsolatedStorageFileStream calls the parameterless base constructor (FileStream()), which results in an not-really-initialized base class. IsolatedStorageFileStream creates an instance of a FileStream and uses it in all methods that it overrides (Write, Read, Flush, Seek, etc.). It is strange that it does not take advantage of its base class directly.

    But Lock and Unlock are not overridden and they need a private field (_handle) that is still null (because the constructor used is the parameterless one). They assume it is non-null and dereference it and cause the NRE.

    To summarize, Lock and Unlock are not supported (or buggy).

    I guess you’re forced to use other lock methods like a Mutex or Semaphore.

    The implementation is the same in .NET 4 RC. In Silverlight, Lock an Unlock are not present at all (my apologies for contradicting an MVP).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I receive error FATAL: could not create lock file postmaster.pid: Permission denied when trying
I have been trying to lock a file so that other cloned services cannot
I am trying to debug multiple threads. *** -[NSLock lock]: deadlock (<NSLock: 0xc388ab0> '(null)')
Premises: I get OverlappingFileLockException every time i try to lock a file (this applies
In my application, I have two queries that occur from time to time (from
I'm trying to lock a file with Java in Windows environment with FileLock and
We're trying to lock down a computer such that we have a generic login
I'm having a hard time trying to 'lock' the depth of nested sortable elements,
I'm trying to remove a lock file and it won't work: ubuntu@ubuntu:/media/My Book/montao$ sudo
I am trying to write a simple lock/unlock algorithm that behaves like a mutex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.