Compiler Warning (level 1) CS1911
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Warning (level 1) CS1911 

Error Message

Access to member 'member' through a 'base' keyword from an anonymous method or iterator results in unverifiable code.

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() {

class Der : B {
   protected override void 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();
      RetD rd = der.DelToBaseM();
© 2015 Microsoft