I have a project in VB.NET targeting the 4.7.2 version of the .NET Framework. Its a ASP WebForms project (yes! poor me) that is deployed to IIS.
Now I’m the process of cleaning up the place. And I was intending to use auto implemented properties in model classes to reduce the amount of, already too much, VB code.
It works fine under development. But I can’t, for the life of me, understand why its not working in the production environment.
The problem boils down the a class like so:
Public Class ValorAtributo
Public Sub New(codigo As String, descricao As String)
Me.Codigo = codigo
Me.Descricao = descricao
End Sub
Public ReadOnly Property Codigo As String
Public ReadOnly Property Descricao As String
End Class
In the IIS production server it fails in the line Me.Descricao = descricao, with the following message:
BC30456: ‘Descricao’ is not a member of
‘PesquisaAtributo.ValorAtributo’.
Investigating the IIS deployment
I’m very much confused by all the .NET flavors and where exactly do they play a role. My understanding here is that IIS uses the .NET CLR and not the .NET Framework. But thats at least half said, along with the previous message, one can see the production IIS is using a different version.
Microsoft .NET Framework Versão:4.0.30319; Versão do
ASP.NET:4.7.3535.0
This is confusing since the web config file only mentions .NET 4.7.2.
<compilation debug="true" strict="false" explicit="true" targetFramework="4.7.2">
...
<httpRuntime targetFramework="4.7.2" maxRequestLength="15360"/>
To add to the confusion, the app pools on IIS only shows .NET up to 4.0 (CLR this time, no mention of .NET Framework I could find).
Atempting a solution
So I need (want) to use auto implemented properties. There must be a fix for this.
My informed guess is that this is caused by an outdated .NET Framework. However I’m not getting what exactly I should do. I’ve read conflicting versions of how exactly this works, IIS uses CLR vs uses .NET. In short, its a mess.
Can anyone of you highly efficient Microsoft devs enlight me in what am I missing here?
updates
looking further
There is a longer trace in the web version of the exception I missed when initially writing the post.
It is very long, SO was playing tricks, here is a pastebin for it. https://pastebin.com/1NhY6SMa
a previous, yet maybe similar? issue
VB Auto Implemented Property not compiling
out of the blue
The code was previously compilling and working fine. I could try and use git to try and figure out what happened, what I cn say for sure is that this file had not changed since.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
That happens because your code is not accessible in output code/library inside your web-app/asp.net.
To resolve:
Right click in your class in project explorer of Visual Studio (in your case is “ValorAtributo”) then
“Properties” then change “Build Action” in “Compile”.
In this mode your class is included in output code.
My IDE is in Italian but you can understand the concept.
Method 2
So. Maybe not an answer to the exact issue. But since no one was able to pinpoint the problem and we do need this up and running, here is our solution.
Don’t use auto properties
Not cheap, but simple. Microsoft is very expensive, avoid it.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
