Share via


컴파일러 경고(수준 1) CS0197

업데이트: 2007년 11월

오류 메시지

'argument'은(는) 참조로 마샬링하는 클래스의 멤버이므로 ref 또는 out으로 전달하거나 해당 주소를 가져오면 런타임 예외가 발생할 수 있습니다.
Passing 'argument' as ref or out or taking its address may cause a runtime exception because it is a field of a marshal-by-reference class

MarshalByRefObject에서 직접 또는 간접으로 파생되는 클래스는 모두 참조로 마샬링하는 클래스입니다. 이러한 클래스는 프로세스와 컴퓨터 경계에 걸쳐 참조로 마샬링할 수 있으므로 이 클래스의 인스턴스는 원격 개체에 대한 프록시일 수도 있습니다. 프록시 개체인 필드는 ref 또는 out을 통해 전달할 수 없습니다. 따라서 인스턴스가 프록시 개체가 될 수 없는 this가 아니면 이러한 클래스의 필드를 ref 또는 out으로 전달할 수 없습니다.

예제

다음 샘플에서는 CS0197 경고가 발생하는 경우를 보여 줍니다.

// CS0197.cs
// compile with: /W:1
class X : System.MarshalByRefObject
{
   public int i;
}

class M
{
   public int i;
   static void AddSeventeen(ref int i)
   {
      i += 17;
   }

   static void Main()
   {
      X x = new X();
      x.i = 12;
      AddSeventeen(ref x.i);   // CS0197

      // OK
      M m = new M();
      m.i = 12;
      AddSeventeen(ref m.i);
   }
}