Daz
Daz

Reputation: 2873

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?

Upvotes: 17

Views: 10352

Answers (7)

Sid
Sid

Reputation: 133

In my case i had to upgrade the the .NET framework. It was on 2.0 and i upgraded it 4.0 after which i was able to add the assembly reference for

and the errors went away

Upvotes: 0

GDavoli
GDavoli

Reputation: 616

In my case (VS2015, ASP.NET app, VB.NET, .NET 4.6) I've solved it by removing the space between the procedure declaration and the Get. The snippet below raises the "Visual Basic 12.0 does Not support ReadOnly auto-implemented properties."

Public ReadOnly Property TestProp() As Integer

    Get
        Return 0
    End Get
End Property

The snippet below does not.

Public ReadOnly Property TestProp() As Integer
    Get
        Return 0
    End Get
End Property

Upvotes: 1

Rafael Neto
Rafael Neto

Reputation: 1290

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

Upvotes: 26

Terry Gibbs
Terry Gibbs

Reputation: 51

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.

Upvotes: 5

Jim Marshall
Jim Marshall

Reputation: 1

Public Interface ICurrentStep
    Private _outerstep As String
    Property outerstep() As String
        Get
            Return _outerstep
        End Get
        Set(ByVal value As String)
            _outerstep = value
        End Set
    End Property
End Interface

Upvotes: 0

GDavoli
GDavoli

Reputation: 616

This may seems trivial and OT, but if you're using Visual Studio Community 2015 and you're targeting .net 3.5 make sure the line continuation "_" has not been automatically removed.

VSC 2015 automatically removes the line continuation upon edit and there's no way to reinsert it back (I had to do it outside of VSC 2015). Furthermore the compiler gives you an error on that line but the editor does not underline it.

Upvotes: 2

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239774

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.

Upvotes: 10

Related Questions