Description
Interned strings are shared across the entire AppDomain. Locking on a string literal can deadlock with unrelated code.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.
String interning creates cross-assembly synchronization, risking deadlocks
public void Update()
{
lock ("myLock") { _count++; }
}
private readonly Lock _syncRoot = new();
public void Update()
{
lock (_syncRoot) { _count++; }
}
dotnet_diagnostic.AL0060.severity = warning
Was this page helpful?
