0

After quite some frustrating research into VB auto properties. I decided to just ignore them. So I had this code.

Public Class Categoria
    Private _nome As String
    Public ReadOnly Property Nome As String
        Get
            Return _nome
        End Get
    End Property

    Public Sub New(nome As String)
        Me._nome = nome
    End Sub
End Class

But Visual Studio, being helpful, suggested to use auto-properties. I agreed, I even tried that before but he offered help in the form of a click here and I will do it. So I did. And he did exactly the same code I was not having any luck with before, char by char.

Public Class Categoria
    Public ReadOnly Property Nome As String

    Public Sub New(nome As String)
        Me.Nome = nome
    End Sub
End Class

Can someone shed some light as to why the last piece of code fails to compile with error BC30126: 'ReadOnly' property must provide a 'Get'.?

Aparently VS is missing the same as I am, so I don't feel so stupid anymore.

Pedro Rodrigues
  • 2,520
  • 2
  • 27
  • 26
  • Your code looks fine and compiles both in my Visual Studio as well as [in dotnetfiddle](https://dotnetfiddle.net/lLkXaI). Is it possible that you somehow (I don't know how one would do this) use an old version of the VB.NET compiler? – Heinzi Jul 28 '20 at 16:46
  • Maybe [have a look at your vbproj file](https://stackoverflow.com/a/32123363/87698). – Heinzi Jul 28 '20 at 16:47
  • @Heinzi Thanks. I'm using VS 2019, installed just a few days ago. The problem is cleary not in the code I post. It's just what I have to show. Some other auto-properties are working in different places. I just cannot figure out why this one wouldn't work. – Pedro Rodrigues Jul 28 '20 at 16:48
  • @Heinzi Its actually a ASP project, is there something equivelant to the vbproj file? I'm not very familiar with ASP, but I'm with the .NET framework in general. Kinda fighting my way atm. – Pedro Rodrigues Jul 28 '20 at 16:49
  • And I tell you that your code is fine, it compiles *perfectly* when I copy & paste it verbatim into my Visual Studio project. What happens if you create a brand new VB project in your Visual Studio and copy & past the code from your question into it? – Heinzi Jul 28 '20 at 16:49
  • 1
    Ah, that changes things. Is it by any chance an ASP.NET web site project? In that case, [you need to tweak your web.config file](https://stackoverflow.com/q/49071549/87698). – Heinzi Jul 28 '20 at 16:50
  • @Heinzi Copy to a new project works fine. – Pedro Rodrigues Jul 28 '20 at 16:51
  • @Heinzi There isn't anything related to _lang_ or _vb_ or anything related to article you post in my web.config file. Not sure what to do there, and I'm a bit scare to touch everytime it breaks something somewhere. The project is a bit old, and picking it up from the dust of another dev, doesn't help either. Do you have any more specific guidelines? – Pedro Rodrigues Jul 28 '20 at 16:56
  • I suggest that you back up your project and then try the steps described in the first answer of my last link step by step. – Heinzi Jul 28 '20 at 17:32
  • @Heinzi Sure. Thank you so much. I'll hit you tomorrow with same feedback. – Pedro Rodrigues Jul 28 '20 at 17:57
  • 1
    Regardless of whether it's the case here, I have seen Visual Studio recommend changes that won't compile once made (VS 2017 in my case). – Craig Jul 28 '20 at 18:27
  • @Craig wait until you get to the circular suggestion of a change. – Pedro Rodrigues Jul 29 '20 at 08:15

1 Answers1

0

As point out by @Heinzi and following a previous post he supplied.

How can I use the latest VB.NET language level in an ASP.NET web site project?

Updating the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package fix it, in my dev machine at least.

Pedro Rodrigues
  • 2,520
  • 2
  • 27
  • 26