JetBrains Rider 2026.1 Help

Code inspection: Captured field reference of a marshal-by-reference class may cause a runtime exception

Fields of a type derived from MarshalByRefObject are not safe to pass by reference. Doing so can fail at runtime even though the code looks valid. This inspection reports ref, out, or in arguments that refer to a field of a marshal-by-reference class.

Example

using System; class DataHolder : MarshalByRefObject { public int Value; } class Example { void Update(ref int x) { } void Test(DataHolder holder) { Update(ref holder.Value); } }
using System; class DataHolder : MarshalByRefObject { public int Value; } class Example { void Update(ref int x) { } void Test(DataHolder holder) { var value = holder.Value; Update(ref value); } }
01 April 2026