Error del compilador CS1618

Actualización: noviembre 2007

Mensaje de error

No se puede crear un delegado con 'método' porque tiene un atributo Conditional
Cannot create delegate with 'method' because it has a Conditional attribute

No puede crear un delegado con un método condicional porque el método puede que no exista en alguna generación.

El código siguiente genera el error CS1618:

// CS1618.cs
using System;
using System.Diagnostics;

delegate void del();

class MakeAnError {
   public static void Main() {
      del d = new del(ConditionalMethod);   // CS1618
      // Invalid because on builds where DEBUG is not set, 
      // there will be no "ConditionalMethod".
   }
   // To fix the error, remove the next line:
   [Conditional("DEBUG")]
   public static void ConditionalMethod() 
   {
      Console.WriteLine("Do something only in debug");
   }
}