I’m trying to compile a POCO with this code
public class MenuItem { public string Name { get; set; } public string Url { get; set; } }
I keep getting compile errors on the gets and sets with messages like: ‘MenuItem.Name.get’ must declare a body because it is not marked abstract or extern. What am I missing? I’m compiling this class in the App_Code folder of a local filesystem web site that is set to compile as .NET 3.5. I know I have done this before, but can’t figure out what I am doing differently.
Make sure your
Web.configfile contains a<system.codedom>subelement under<configuration>element like this:The problem arises from the fact that ASP.NET is running the old version of C# compiler to compile your application (v2.0) which does not support automatic properties. In order to use .NET 3.5 features, you have to specify the compiler version in your
Web.configexplicitly.