Description
typeof(T) returns a globally shared Type object. Locking on it creates cross-assembly deadlock risks.
Bad Code
Good Code
Properties
- Category: Threading
- Severity: Warning
- Enabled by default: True
- Code fix available: False
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Type objects are global singletons, risking cross-assembly deadlocks
typeof(T) returns a globally shared Type object. Locking on it creates cross-assembly deadlock risks.
public void Update()
{
lock (typeof(MyService)) { _count++; }
}
private static readonly object s_lock = new();
public void Update()
{
lock (s_lock) { _count++; }
}
dotnet_diagnostic.AL0059.severity = warning
Was this page helpful?
