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 6668909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:05:30+00:00 2026-05-26T03:05:30+00:00

I have a situation whereby ReadWriterLockSlim is throwing the exception System.Threading.SynchronizationLockException – The write

  • 0

I have a situation whereby ReadWriterLockSlim is throwing the exception “System.Threading.SynchronizationLockException – The write lock is being released without being held.” when I try to execute ExitWriteLock(). As far as I can tell, this shouldn’t happen because subsequent threads that enter the try block will ‘block’ until they can obtain the lock. Am I missing something here?

The issue looks very similar to this one, however no solution was posted there.

//Code simplified for example. 

public class i18nService {
    internal static ReaderWriterLockSlim cacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);

    private string ProcessText()
    {
        try {
            cacheLock.EnterWriteLock();
            return "xyz";
        }
        finally {
            cacheLock.ExitWriteLock(); // Error is throwing here. 
        }
    }
}

Thanks very much for your help 🙂

  • 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-26T03:05:31+00:00Added an answer on May 26, 2026 at 3:05 am
        try {
            cacheLock.EnterWriteLock();
            return "xyz";
        }
        finally {
            cacheLock.ExitWriteLock(); // Error is throwing here. 
        }
    

    Q: What happens if cacheLock.EnterWriteLock(); fails?

    A: The finally statement gets executed.

    • cacheLock.ExitWriteLock(); gets called
    • But we don’t have the lock

    Try this:

    private string ProcessText()
    {
        cacheLock.EnterWriteLock();
        try {
            return "xyz";
        }
        finally {
            cacheLock.ExitWriteLock(); // Error is throwing here. 
        }
    }
    

    Presumably .NET is designed in such a way that if EnterWriteLock() fails, the lock is released (or never held at all).

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

Sidebar

Related Questions

I am in a situation whereby I have two sites, one a sub-domain of
We are in a situation whereby we have 4 developers with a bit of
We have a situation at work where developers working on a legacy (core) system
I have a situation whereby an application we use has many databases used for
I have a situation whereby a company is providing me an xml file with
I have a situation whereby when a page loads, I send some authentication data
I have an application which models the electrical distribution of a system whereby if
I have a situation whereby I'm populating an ArrayList with TransactionEvent s. TransactionEvent has
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation, where running a query that filters by an indexed column in

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.