Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Visual Basic 10.0 does not support readonly auto-implemented properties" error in Visual Studio 2015

I've inherited a VB.NET Web Site project that targets version 4 of the .NET framework which includes the following line:

Public ReadOnly Property Foo(Optional ByVal MyShort As Short = -1, Optional ByVal MyBool As Boolean = True) As String
     Get
         'logic
         return Bar
     End Get
End Property

I'm using Visual Studio 2015 and can't build the project with that line in place because the I'm getting the error "Visual Basic 10.0 does not support readonly auto-implemented properties".

I came across this question that describes an error "VB 9 does not support auto-implemented properties" and points to a bug in the Roslyn compiler and suggests moving as much as possible outside of App_Code to avoid the issue.

Has anyone run into this error and found a relatively painless way around it?

I've considered making the case for changing the property into a function because that seems logical when it's a readonly property with internal logic that takes optional arguments; in this case I don't know that it will be permissible to move anything out of App_Code.

like image 585
Branden Schwartz Avatar asked May 12 '16 13:05

Branden Schwartz


1 Answers

I don't know about that bug, nor how to bypass it, but the question of changing this property to a method makes sense.

The question I would ask is: "Should this property be a method in the first place?"

Here is some reading about that question.

Besides that, you always can turn a property to a method, but you'll loose some capabilities (see this answer)

like image 136
Martin Verjans Avatar answered Nov 11 '22 10:11

Martin Verjans