.NET属性生成“必须声明一个主体,因为它没有标记为abstract或extern”编译错误 [英] .NET property generating "must declare a body because it is not marked abstract or extern" compilation error

查看:2604
本文介绍了.NET属性生成“必须声明一个主体,因为它没有标记为abstract或extern”编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET 3.5(目标框架)Web应用程序。我有一些代码看起来像这样:

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."

任何想法?我的理解是,这种风格的属性是有效的.NET 3.0。

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

谢谢!

问题出在我的.sln文件本身。虽然我在我的构建选项更改目标版本,在.sln文件中,我发现:

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"

将其更改为3.5即可解决问题。非常感谢!

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

推荐答案

添加到web.config

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>

这篇关于.NET属性生成“必须声明一个主体,因为它没有标记为abstract或extern”编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆