Code inspection: Captured reference to 'volatile' field will not be treated as 'volatile'
Passing a volatile field by reference removes the usual volatile access guarantees inside the called method. This can make synchronization code misleading or unsafe.
This inspection reports ref and out arguments that pass a volatile field by reference, except for special cases such as supported interlocked APIs.
The inspection is effectively the same as the CS0420 compiler warning.
Example
class Example
{
private volatile int _value;
void Update(ref int x) { }
void Test()
{
Update(ref _value);
}
}
class Example
{
private volatile int _value;
void Update(ref int x) { }
void Test()
{
var value = _value;
Update(ref value);
}
}
Quick-fix
The quick-fix introduces a local variable and passes that variable instead.
01 April 2026