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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:01:16+00:00 2026-06-02T19:01:16+00:00

I got this exception The read lock is being released without being held. at

  • 0

I got this exception
The read lock is being released without being held.
at System.Threading.ReaderWriterLockSlim.ExitReadLock()
at .. GetBreed(String)

Below is the only place in code that accesses the lock. As you can see, there is no recursion. I’m having trouble understanding how this exception could occur.

static readonly Dictionary<string, BreedOfDog> Breeds 
     = new Dictionary<string,BreedOfDog>();

static BreedOfDog GetBreed(string name)
{
        try
        {
            rwLock.EnterReadLock();
            BreedOfDog bd;
            if (Breeds.TryGetValue(name, out bd))
            {
                return bd;
            }
        }
        finally
        {
            rwLock.ExitReadLock();
        }

        try
        {
            rwLock.EnterWriteLock();
            BreedOfDog bd;
            //make sure it hasn't been added in the interim
            if (Breeds.TryGetValue(t, out bd)
            {
                return bd;
            }
            bd = new BreedOfDog(name); //expensive to fetch all the data needed to run  the constructor, hence the caching

            Breeds[name] = bd;
            return bd;
        }
        finally
        {
            rwLock.ExitWriteLock();
        }
}  
  • 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-06-02T19:01:18+00:00Added an answer on June 2, 2026 at 7:01 pm

    I’m guessing you have something re-entrant, and it is throwing an exception when obtaining the lock. There is a catch-22 whether you “take the lock”, “try” vs “try”, “take the lock”, but the “take the lock”, “try” has fewer failure cases (the “aborted between take and try” is so vanishingly unlikely you don’t need to stress).

    Move the “take the lock” outside the “try”, and see what the actual exception is.

    The problem is most likely that you are failing to take the lock (probably re-entrancy), then trying to unlock something you didn’t take. This could mean that the exception surfaces in the orginal code that took the lock, due to trying to release twice when only taken once.

    Note: Monitor has new overloads with “ref bool” parameters to help with this scenario – but not the other lock types.

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

Sidebar

Related Questions

I got this exception ... EntityCategoryProxy could not be converted to int in ...
I got this error Unhandled exception at 0x0049b946 in Program.exe: 0xC0000005: Access violation reading
I got this error message and I'm not quite sure whats wrong: Exception in
i got a webservicedefinition like this: [OperationContract] [FaultContract(typeof(Exception))] [WebInvoke(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped,
I got this from a Soap client request: Exception: SoapFault exception: [soap:Client] Server was
I read that this exception means that I added a LinearLayout that had no
I am getting the following exception. java.util.NoSuchElementException: No line found I got this error
Got this line of code here but its not working. private void Button_Click(object sender,
Got this site with UN/PW set via the Createuserwizard control. Client considers PW too
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID

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.