Alex Rivera | Logout

.NET property generating "must declare a body because it is not marked abstract or extern" compilation error

Asked 2008-09-18T18:56:13.907
12

I have a .NET 3.5 (target framework) web application. I have some code that looks like this:

public string LogPath { get; private set; }
public string ErrorMsg { get; private set; }

It's giving me this compilation error for these lines:

"must declare a body because it is not marked abstract or extern."

Any ideas? My understanding was that this style of property was valid as of .NET 3.0.

Thanks!


The problem turned out to be in my .sln file itself. Although I was changing the target version in my build options, in the .sln file, I found this:

TargetFramework = "3.0"

Changing that to "3.5" solved it. Thanks, guys!

Edit
Report

3 Answers

16

add to web.config

<system.codedom>
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
            <providerOption name="CompilerVersion" value="v3.5" />
            <providerOption name="WarnAsError" value="false" />
        </compiler>
    </compilers>
</system.codedom>
answered 2009-07-16T21:28:59.887
0

This also happens on a raw web site project where there was no web.config generated.

Although the solution file said 3.5, .Net needed the web.config to state it also to recognize. I ran debug allowing it to create a webconfig, and all was working.

So it is like the answer provided, but just make sure you have one.

answered 2009-08-25T19:46:05.717
-7

It is, as long as you put abstract in front, or implement the methods.

public abstract string LogPath { get; private set; }
public abstract string ErrorMsg { get; private set; }

See http://forums.asp.net/t/1031651.aspx

answered 2008-09-18T18:59:04.510

Your Answer