.NET - Error trying to compile automatic properties

I am trying to compile POCO with this code

public class MenuItem { public string Name { get; set; } public string Url { get; set; } } 

I keep getting compilation errors in sets and sets with messages such as: 'MenuItem.Name.get' should declare the body because it is not marked abstract or external. What am I missing? I compile this class in the App_Code folder on the local file system website, which is configured to compile as .NET 3.5. I know that I did this before, but I can’t understand what I am doing differently.

+4
source share
1 answer

Make sure your Web.config file contains the <system.codedom> in the <configuration> element, for example:

 <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="WarnAsError" value="false"/> </compiler> </compilers> </system.codedom> 

The problem arises because ASP.NET launches an old version of the C # compiler to compile your application (v2.0), which does not support automatic properties. To use the features of .NET 3.5, you must explicitly specify the compiler version in your Web.config .

+12
source

All Articles