Compiler Error CS1946
Collapse the table of content
Expand the table of content

Compiler Error CS1946


An anonymous method expression cannot be converted to an expression tree.

An anonymous method represents a set of statements but an expression tree must not contain a statement. Therefore an anonymous method cannot be represented by an expression tree.

To correct this error

  1. Change the anonymous method to a lambda expression.


The following example generates CS1946:

// cs1946.cs
using System;
    using System.Linq.Expressions;

    public delegate void D();

    class Test
        static void Main()
            Expression<D> tree = delegate() { }; //CS1946
            // Try using a lambda expression instead.
            // Expression<D> tree = (x) => x + 1;
© 2016 Microsoft