Compiler Warning (level 1) CS1690

Accessing a member on 'member' may cause a runtime exception because it is a field of a marshal-by-reference class

This warning occurs when you try to call a method, property, or indexer on a member of a class that derives from MarshalByRefObject, and the member is a value type. Objects that inherit from MarshalByRefObject are typically intended to be marshalled by reference across an application domain. If any code ever attempts to directly access the value-type member of such an object across an application domain, a runtime InvalidOperationException will occur. To resolve the warning, first copy the member into a local variable and call the method on that variable.

The following sample generates CS1690:

// CS1690.cs  
using System;

class WarningCS1690 : MarshalByRefObject
    int i = 5;

    public static void Main()
        AppDomain domain = AppDomain.CreateDomain("MyDomain");
        Type t = typeof(WarningCS1690);
        WarningCS1690 e = (WarningCS1690)domain.CreateInstanceAndUnwrap(t.Assembly.FullName,t.FullName);

        e.i.ToString(); // CS1690

        // OK  
        int i = e.i;
        e.i = i;