Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Expression cannot contain anonymous methods or lambda expressions
You cannot insert an anonymous method inside an expression.
To correct this error
- Use a regular delegate in the expression.
Example
The following example generates CS1706.
// CS1706.cs
using System;
delegate void MyDelegate();
class MyAttribute : Attribute
{
public MyAttribute(MyDelegate d) { }
}
// Anonymous Method in Attribute declaration is not allowed.
[MyAttribute(delegate{/* anonymous Method in Attribute declaration */})] // CS1706
class Program
{
}