1

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"/>

IIS Application Pools 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

enter image description here

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.

Pedro Rodrigues
  • 2,520
  • 2
  • 27
  • 26
  • 1
    Have you installed ASP.NET4.7 and .NET Extensibility4.7 via Windows Features for IIS? – Alex B. Aug 04 '20 at 14:05
  • @AlexB. Hi, I've added a screenshot of the features installed. I'm not sure if that is that right place to look, but there is no option for ASP 4.7. Installing .NET 4.7.2 Runtime says a newer version is installed. – Pedro Rodrigues Aug 04 '20 at 14:21
  • 1
    What OS is running your IIS? – Alex B. Aug 04 '20 at 14:28
  • @AlexB. Windows Server 2016 Standard – Pedro Rodrigues Aug 04 '20 at 14:32
  • 1
    [This](https://support.microsoft.com/en-us/help/4054530/microsoft-net-framework-4-7-2-offline-installer-for-windows) installer is for MS Servcer 2012, 2016 and Win 10 etc. – Alex B. Aug 04 '20 at 14:34
  • @AlexB. .NET 4.7.2 or a later version is already installed. _This is a translation of the pportuguese message_. That was with your link. – Pedro Rodrigues Aug 04 '20 at 14:39
  • 1
    Hmm strange. You could try un- and reinstall 4.7.2. But I´m out of ideas. – Alex B. Aug 04 '20 at 14:45
  • @AlexB. Fair enough. Thanks. – Pedro Rodrigues Aug 04 '20 at 14:49
  • @AndrewMorton Files are copied using git hooks, so whatever is in git gets to the server. I did try to copy my local bin folder, to no help. I'll get back to you tomorrow with the web.config trick you have. Thanks. – Pedro Rodrigues Aug 04 '20 at 18:13
  • @AndrewMorton Got you. And this just gets weirder and weirder. There ain't any project properties, see http://i.imgur.com/8Sk3m42.png. However, there are for the solution, see http://i.imgur.com/Rms1YUH.png. But nothing like a _compile tab_ to be found, see http://i.imgur.com/t7UaANv.png. I did fiddle around on the screen from the last shot, but no luck with the `strict` thing. I couldn't imagine such option doing anything else than changing the `web.config` `strict` parameter to `true/false`, which I have already tried. – Pedro Rodrigues Aug 04 '20 at 20:17
  • @PedroRodrigues You can put `Option Strict On` as the first line in the code (\*.vb) files if it is being awkward about enforcing it for you. However, I still think that uploading *all* the files again is more likely to make it work. – Andrew Morton Aug 04 '20 at 20:47
  • @AndrewMorton Copying my local dir didn't work. Adding the `Option Strict On` line to the offending file didn't work. Still the exact error. – Pedro Rodrigues Aug 05 '20 at 08:14
  • @PedroRodrigues How is it being called? Have you tried adding a default (i.e. parameterless) constructor? – Andrew Morton Aug 05 '20 at 09:39

2 Answers2

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.enter image description here My IDE is in Italian but you can understand the concept.

G3nt_M3caj
  • 2,497
  • 1
  • 14
  • 16
  • Hi thanks. Most the picture I posted are in portuguese.. so no problem. However, I may have missed some important pieces in the original question; it has been updated to add those (chec the pastebin). In direct regards to your answer, I do not have a `Properties` option in the `Solution Explorer` as you do, if it all relevant there a bunch of classes in the same file (also a bit different than you show). – Pedro Rodrigues Aug 04 '20 at 14:37
  • If you move mouse up to this file then you click right click of the mouse do you have any mini-window with some options where on of those is "Properties" or something like that? – G3nt_M3caj Aug 04 '20 at 14:44
  • If you mean the context window. No. There is no properties option If I right click the .vb file, there is no `Properties` option. I understood your suggestion, but there is no `Properties` option. I can open the Properties tab with the file selected, but then there none of the options you show. – Pedro Rodrigues Aug 04 '20 at 14:49
  • Can you post an image of this Properties you are talking about? – G3nt_M3caj Aug 04 '20 at 14:50
  • I mean Visual Studio not IIS. – G3nt_M3caj Aug 04 '20 at 14:52
  • The context menu in Solution Exlorer https://prnt.sc/ttwuh2 (The class is in `Model.vb`). If I keep the file selected and switch to the Properties tab https://prnt.sc/ttwv89 – Pedro Rodrigues Aug 04 '20 at 14:54
  • Get that class and put that in another file just for a try then repeat those operations → right click of mouse → preoperties → build action to Compile. Check other files, do these have an option called “Build action” ? – G3nt_M3caj Aug 04 '20 at 15:05
  • I did try that when you initially replied. https://prnt.sc/ttx6lv weird af – Pedro Rodrigues Aug 04 '20 at 15:10
  • Oh sorry. By the icon of your project I figure out your project is a “Web Site” and not a “Web Application”. You have not Compilation option for your files in this case as is all considered as content. However Now I see more in detail your code. You cannot Set a ReadOnly Property in your New declaration class. So, just remove “ReadOnly” specification. – G3nt_M3caj Aug 04 '20 at 15:27
  • Well. That is cleary not right as the code works fine in a lab environment. I'm more familiar with C# and, as long as it is in the constructor, you can assign to a readonly field. This is for VB, search for `constructor` https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/modifiers/readonly – Pedro Rodrigues Aug 04 '20 at 15:32
  • Have 0 clue what a web application is vs a web site. What I do know is, this is old and poorly maintained. – Pedro Rodrigues Aug 04 '20 at 15:32
  • Yes this is partially true. Depends also in your IDE version. My VS 2019 allow to do that but my VS 2013 doesn't allow. It's depends on Intellicode version VS/Compiler have – G3nt_M3caj Aug 04 '20 at 15:35
  • 1
    For differences about web apps and web sites you can take a look here https://learn.microsoft.com/en-us/previous-versions/aspnet/dd547590(v=vs.110) – G3nt_M3caj Aug 04 '20 at 15:38
0

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.

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