Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Visual Basic 9.0 does not support auto-implemented properties" on an interface in Visual Studio 2015 RC

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

I have this interface defined:

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

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

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.

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

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?

like image 227
Daz Avatar asked Jul 01 '15 11:07

Daz


3 Answers

In my case, using VS2015 Community, the real problem was a blank line between the property header and the Get method. See my screenshots below:

Before: (Error image)

enter image description here

After: (No error image)

enter image description here

like image 128
Rafael Neto Avatar answered Nov 11 '22 06:11

Rafael Neto


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.

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.

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

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.


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)

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.

like image 10
Damien_The_Unbeliever Avatar answered Nov 11 '22 06:11

Damien_The_Unbeliever


I have a project that is in the process of moving to use VS2015 from VS2008. We need to support both environments in the short term so I have created VS015 .vbproj files that include the directive 9 in the PropertyGroup section of the file.

I was getting this error because there was a comment between the Property declaration and the Get clause. For example

Private ReadOnly Property MemberNode() As XmlNode</br>
    ' This is the only place which locates the objMember node
    Get
        Return CreatePathAndNode(mnodMessage, "objData/colMember/objMember")
    End Get 
End Property

Moving the comment before the "Private Readonly" line removed the compiler error in VS2015.

like image 5
Terry Gibbs Avatar answered Nov 11 '22 05:11

Terry Gibbs