14

My VB skills are not the best, and this problem has had me stumped for a few days.

In the list of controls shown in Visual Studio that are not defined in the code behind, I can "mouseover" them and the tooltip text pops right up.

popup

errors

screenshot

Similar questions:

This one had no solution - 'var_name'is not declared. It may be inaccessible due to its protection level.' in debug mode

This one said the solution was in the web.config, but I don't understand where/how - BC30451: 'MailValidation' is not declared. It may be inaccessible due to its protection level

This one was a misspelled word - vb.net error: inaccessible due to its protection level

Update - Here is another problem that might be a clue to what my problems are:

In my Tools.vb module, I have a class to access LDAP.

The namespace for the tools class is given in the login.aspx.vb code, yet login code does not recognize the tools class.

missing tools

Community
  • 1
  • 1
  • 1
    I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 01 '14 at 23:13
  • 3
    Since you've reached the maximum number of errors, it's very likely that there's something else in that list that's the cause of all of the others. Look closer to the bottom of that list for a different type of error that stands out from the others. – Cᴏʀʏ Dec 01 '14 at 23:14
  • 1
    Did you `Clean Solution`, then `Rebuild Solution`? – OneFineDay Dec 01 '14 at 23:43
  • Also always have a backup for your solution and save changes with stable updates, and save often. – OneFineDay Dec 01 '14 at 23:44
  • @OneFineDay - I do a clean build every time. –  Dec 02 '14 at 17:40
  • Also, the solution comes out of source control (I did not create it). –  Dec 02 '14 at 17:40
  • @Cory - I cannot find the source of the problem because I only see these errors followed by a single entry for *"Maximum number of errors has been exceeded."* –  Dec 02 '14 at 17:41
  • @jp2code: Something, somewhere, is not compiling. Because it can't compile, your controls don't know what they are. You could have a .NET framework version mismatch, a missing reference, a file in use and inaccessible to the compiler, or even simply a syntax error. Does your solution contain multiple projects? You might try opening a single project and compiling that. – Cᴏʀʏ Dec 02 '14 at 18:38
  • @Cory I'm assuming .Net 2.0 was used, since that is what the application pool is set to. The original project does not exist in version control - just the published files. This solution only contains a single project, but I can't even get classes (modules in VB) to be recognized in the code behind. –  Dec 02 '14 at 21:26
  • @jp2code: An application pool specifies compiler version, so the project could be 2.0, 3.0, or 3.5. – Cᴏʀʏ Dec 02 '14 at 21:37
  • @Cory - I posted an update with another screenshot. Does this reveal anything to you that I might be overlooking? (my project is set to 2.0). –  Dec 02 '14 at 21:46
  • @jp2code I have a question similar to this. Could you check it out? http://stackoverflow.com/q/36846873/2465664 – ic3man7019 Apr 26 '16 at 14:24

8 Answers8

6

Pay close attention to the first part of the error: "variable is not declared"

Ignore the second part: "it may be inaccessible due to its protection level". It's a red herring.

Some questions... (the answers might be in that image you posted, but I can't seem to make it larger and my eyes don't read that small of print... Any chance you can post the code in a way these older eyes can read it? Makes it hard to know the total picture. In particular I am suspicious of your Page directives.)

We know that 1stReasonTypes is a listbox, but for some reason it seems like we don't know WHICH listbox. This is why I want to see your page directives.

But also, how are you calling the private method FormRefresh()? It's not an event handler, which makes me wonder if you are trying to reference a listbox in a form that is not handled properly in this code behind.

You may need to find the control 1stReasonTypes. Try maybe putting your listbox inside something like

<div id="MyFormDiv" runat="server">.....</div>

then in FormRefresh(), do a...

Dim 1stReasonTypesNew As listbox = MyFormDiv.FindControl("1stReasonTypes")

Or use an existing control, object, or page instead of a div. More info on FindControl: http://msdn.microsoft.com/en-us/library/486wc64h(v=vs.110).aspx

But no matter how you slice it, there is something funky going here such that 1stReasonTypes doesn't know which exact listbox it's supposed to be.

Casey Crookston
  • 13,016
  • 24
  • 107
  • 193
  • 1
    You were adding your update as I was typing. Off hand, not sure why you can't import FormsAuth. Maybe try cutting all of FormsAuth from Tools. Then creating a brand new class file called FormsAuth.vb, paste FormsAuth into the new class. But, I'm not sure this is the same problem as your listbox issue. – Casey Crookston Dec 02 '14 at 22:19
  • Oddly enough, that is exactly what I did with the **admin_reasons.aspx** file with the `lstReasonTypes` error: I created a new file with almost the exact same name, copied and pasted all of the text from the HTML and code behind into that new file, and it had no problems. This project has about 40 files, though, so I hope I don't have to do that with each of them. :( –  Dec 02 '14 at 22:33
  • Like some of the other comments above, something seems off with this solution. I've seen stuff like this before, where something somewhere gets corrupted and it takes a while to sort it out. Based on the sheer number of errors you get when trying to compile, I don't think you've yet found the real issue yet. 40 files is a lot, but it's not intolerable. If you get desperate, you may want to create a new project and a new solution and start porting over the files one at a time, starting with the class files, and making sure you can build often along the way. – Casey Crookston Dec 02 '14 at 22:40
  • I would, but this project is a critical part of business here (timecards). Unfortunately, it is on a 2000 server that is supposed to go offline Jan. 1. I'm supposed to have it up by then ...and I didn't write this mess! {argh!} –  Dec 02 '14 at 22:42
  • You know, actually creating new forms then copying and pasting the HTML and code into them isn't taking that long. I'll let you know how it goes. –  Dec 02 '14 at 23:07
  • yeah, it goes pretty fast once you get rolling. I've had to do this a couple times when a project gets mucked up. – Casey Crookston Dec 02 '14 at 23:25
4

I have suffered a similar problem, with a Sub not accessible in runtime, but absolutely legal in editor. It was solved by changing destination Framework from 4.5.1 to 4.5. It seems that my IIS only had 4.5 version.

:)

Javier
  • 41
  • 3
  • 1
    So the answer is to use a more recent version of the Framework? If yes, please indicate it more clearly. – Martin Zabel Feb 24 '16 at 16:50
  • Microsoft is ending 4.5.1. Perhaps it was buggy. That project in my original post has long since shipped and we do not have the code any longer. So, I cannot verify if your solution solves the problem. –  Feb 24 '16 at 18:37
2

If I remember correctly, this is the default property for controls.

Can you try by going into Design-View for the admin_reasons that contains the specified Control, then changing the control's Modifiers property to Public or Internal.

Trevor
  • 7,777
  • 6
  • 31
  • 50
  • That shouldn't be necessary, but I'll try it out. Every control in every page of the project does it, though. –  Dec 02 '14 at 14:39
  • OK, that did not work. Apparently on a web page, all controls are already public. –  Dec 02 '14 at 17:42
2

I had a similar issue to this. I solved it by making all the projects within my solution target the same .NET Framework 4 Client Profile and then rebuilding the entire solution.

Joseph Mawer
  • 288
  • 6
  • 16
1

I got this error briefly after renaming the App_Code folder. Actually, I accidentally dragged the whole folder to the App_data folder. VS 2015 didn't complain it was difficult to spot what had gone wrong.

Tom McDonald
  • 1,532
  • 2
  • 18
  • 37
1

I have found that you have to comment out the namespace wrapping the the class at time when moving between version of Visual Studio:

'Namespace FormsAuth

'End Namespace

and at other times, I have to uncomment the namespace.

This happened to me several times when other developers edited the same solution using a different version of VS and/or I moved (copied) the solution to another location

dee.ronin
  • 1,040
  • 12
  • 22
Bob Kiefer
  • 11
  • 1
1

This error occurred for me when I mistakenly added a comment following a line continuation character in VB.Net. I removed the comment and the problem went away.

DeveloperDan
  • 4,626
  • 9
  • 40
  • 65
0

Im my case the error was produced because an assembly used by several other assemblies was at .NET 4.5 instead of .NET 4.7, probably in the GAC. There was as version miss match in the global reference tree of my solution.

I included the source code of the assembly in error, modified its version to .NET 4.7 and made sure all other assemblies in my solution pointed toward this verstion. I also "neutralized" the one in the GAC, by renaming it with an underscore as the first letter.

gharel
  • 413
  • 4
  • 13