## Why is this an issue?

Objects that can be accessed across application domain boundaries are said to have weak identity. This means that these objects can be considered shared resources outside of the domain, which can be lead to them being accessed or modified by multiple threads or concurrent parts of a program, outside of the domain.

A thread acquiring a lock on such an object runs the risk of being blocked by another thread in a different application domain, leading to poor performance and potentially thread starvation and deadlocks.

Types with weak identity are:

- MarshalByRefObject
- ExecutionEngineException
- OutOfMemoryException
- StackOverflowException
- String
- MemberInfo
- ParameterInfo
- Thread

## How to fix it

### Code examples

#### Noncompliant code example

    public class Sample
    {
        private readonly StackOverflowException myLock = new();

        public void Go()
        {
            lock (myLock) // Noncompliant
            {
                // ...
            }
        }
    }

#### Compliant solution

    public class Sample
    {
        private readonly object myLock = new();

        public void Go()
        {
            lock (myLock)
            {
                // ...
            }
        }
    }

## Resources

### Documentation

- Thread
- Locking
- Deadlock
- Managed Threading Best Practices
- Application domains

### Articles & blog posts

- What is (thread) starvation?
- Readers-writers problem
- Dining philosophers problem