Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C#
C# Reference
 Compiler Warning (level 1) CS1911
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual C# Reference: Errors and Warnings
Compiler Warning (level 1) CS1911

Error Message

Access to member 'name' through a 'base' keyword from an anonymous method, lambda expression, query expression, or iterator results in unverifiable code. Consider moving the access into a helper method on the containing type.

Calling virtual functions with the base keyword inside the method body of an iterator or anonymous methods will result in unverifiable code. Unverifiable code will fail to run in a partial trust environment.

One resolution for CS1911 is to move the virtual function call to a helper function.

The following sample generates CS1911.

// CS1911.cs
// compile with: /W:1
using System;

delegate void D();
delegate D RetD();

class B {
   protected virtual void M() {
      Console.WriteLine("B.M");
   }
}

class Der : B {
   protected override void M() {
      Console.WriteLine("D.M");
   }

   void Test() { base.M(); }
   D Test2() { return new D(base.M); }

   public D CallBaseM() {
      return delegate () { base.M(); };   // CS1911

      // try the following line instead
      // return delegate () { Test(); };
   }

   public RetD DelToBaseM() {
      return delegate () { return new D(base.M); };   // CS1911

      // try the following line instead
      // return delegate () { return Test2(); };
   }
}

class Program {
   public static void Main() {
      Der der = new Der();
      D d = der.CallBaseM();
      d();
      RetD rd = der.DelToBaseM();
      rd()();
   }
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker