错误"Visual Basic 9.0不支持自动实现的属性";在Visual Studio 2015 RC中的界面上 [英] Error "Visual Basic 9.0 does not support auto-implemented properties" on an interface in Visual Studio 2015 RC

查看:136
本文介绍了错误"Visual Basic 9.0不支持自动实现的属性";在Visual Studio 2015 RC中的界面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开了一个网站项目,该项目以前是在2015年RC的Visual Studio 2012中开发的.该项目的目标是.net 3.5.

I have opened a website project that has previously been developed in Visual Studio 2012 in 2015 RC. The project targets .net 3.5.

我定义了以下接口:

Public Interface ICurrentStep
    Property outerstep() As String
    Property innerstep() As String
End Interface

对于每个属性,我都会收到以下构建错误:"BC36716 Visual Basic 9.0不支持自动实现的属性."

I get the following build error for each property: "BC36716 Visual Basic 9.0 does not support auto-implemented properties."

我不明白为什么Visual Studio 2012对此感到完全满意,而2015年却不满意.该网站在.net 3.5下的xcopy和已发布版本中均能正常工作.

I don't understand why Visual Studio 2012 is perfectly happy with this but 2015 is not. The website works fine under .net 3.5 in both xcopy and published versions.

我也不了解如何以其他方式定义接口.这可能是2015/Roslyn的错误吗?

I also don't understand how would I define the interface any other way. Could this be a 2015/Roslyn bug?

定向.net 4.0确实解决了问题,但是由于某些外部依赖性,目前尚不能部署.我认为这是因为根据

Targeting .net 4.0 does remove the problem but that's not an option for deployment at the moment due to some external dependencies. I presume that's because behind the scenes it's targeting a different compiler as per Is it possible to force Visual Studio 2010 to use Visual Basic 10?

推荐答案

这确实确实是Roslyn编译器中的错误.编译器以一种奇怪的模式运行,在该模式下,它检查(但不是真正地编译) App_Code 中的代码-该代码实际上是在站点启动时被编译的.

This does indeed appear to be a bug in the Roslyn compiler. The compiler is running in an odd mode where its checking (but not really compiling) the code within App_Code - that code actually gets compiled when the site starts up.

由于它知道您已将代码设置为在v3.5下运行,因此它假定该代码实际上将由"v2.0"编译器进行编译,因此它可以像运行已指定 /langversion 标记为9.

Since it knows that you've set the code to run under v3.5, it assumes that the code will actually be compiled by the "v2.0" compiler, so it's effectively running the check/compile as if you've specified the /langversion flag as 9.

因此,这就是错误消息谈论Visual Basic 9不支持的事情的原因.但是,如果使用真正的VB9编译器编译代码,那么它当然可以编译.

So, that's why the error message is talking about things not supported by Visual Basic 9. However, if you compile the code with real VB9 compiler, it of course compiles fine.

为证明编译器相当混乱,我将您的示例更改为:

As evidence that the compiler is rather confused, I changed your sample to:

Public Interface ICurrentStep
    Property outerstep() As String = "Hello"
    Property innerstep() As String
End Interface

这会产生一个错误,提示您在接口中不允许初始化程序.但是,不仅仅是两条错误消息指出"Visual Basic 9.0不支持自动实现的属性".我们收到错误无法初始化扩展属性".但是,这没有道理:

This should produce an error about not being allowed an initializer in an interface. However, instead of just two error messages stating "Visual Basic 9.0 does not support auto-implemented properties." we also get the error "Expanded Properties cannot be initialized.". But, this does not make sense:

在某些情况下,您不能使用自动实现的属性,而必须使用标准或扩展的属性语法.

there are situations in which you cannot use an auto-implemented property and must instead use standard, or expanded, property syntax.

也就是说,一个属性可以 自动实现或扩展.

That is, a single property can either be auto-implemented or expanded.

我的建议是将尽可能多的代码移出 App_Code -要么移出它,要么移到另一个库中.这将意味着该代码实际上是由Roslyn编译器直接编译的(并且没有/langversion 设置),并且您实际上可以开始使用现代VB功能了(仍然可以针对v3.5但使用以后的语言功能)

My recommendation would be to move as much code as possible out of App_Code - either just outside of it or into a different library. This will then mean that the code is actually compiled by the Roslyn compiler directly (and without the /langversion setting) and that you can actually start making using of modern VB features (you can still target v3.5 but use later language features)

或者,您可以将代码保留在 App_Code 中,然后选择忽略错误.如果只是两个错误,那从短期来看可能是可行的.

In the alternative, you can leave the code in App_Code and choose to ignore the errors. If it's just two errors, that may be feasible in the short term.

这篇关于错误"Visual Basic 9.0不支持自动实现的属性";在Visual Studio 2015 RC中的界面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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