none
strange behavior in watch list

    Question

  • I'm getting a behavior in the watch list that I can't explain. While examining an object in the watch list, its value collumn reads "'VariableName' is not declared. It may be inaccessible due to its protection level." This is from a break point after it has been declared and initialized. For example:

    Dim a As New List()

    -- break point here ----

    At first I though there was a problem with my custom objects but I get the same thing with any and all framework objects. It does not do this with value objects but if the value objects are declared after the class objects I get the same error. I tried rebooting and I can't get it back to its normal behavior. Could this be a VS2010 bug?

     

     

    Sunday, May 23, 2010 12:31 AM

All replies

  • More info on this problem.

    I removed the project's reference to the Linq library and removed the imported namespace to it as well. The problem went away although I still cant explain it. I happen to not need Linq in my project but what if I did?

    Sunday, May 23, 2010 8:17 AM
  • Hello Perry,

    Thanks for your thread!

    It's a strange behavior. Unfortunately, it can not be reproduced on my Visual Studio 2010. I created a new VB Console project and tested with a code snippet as below:

    Imports System.Linq
    Imports System.Data.Linq
    Imports System.Xml.Linq
    
    Module Module1
    
      Sub Main()
        Dim a As New List(Of MyTestClass)
        Dim mtc As MyTestClass = New MyTestClass() 'set a breakpoint here.
        tc.Name = "Hello"
        a.Add(tc)
        'other work...
      End Sub
    
    End Module
    

    If I missed something, please correct me. We'd be really appreciated if you can provide us a code snippet to reproduce the issue. I ask for this because, to confirm if it is a bug, we need to reproduce it for trouble shooting. Hope you could understand.

    If you have a project which can reproduce it, you could submit a bug report directly via connect site.

    Thanks


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Proposed as answer by Roahn Luo Friday, May 28, 2010 5:02 AM
    Monday, May 24, 2010 3:24 AM
  • Today I got the error again even after removing the Linq references. So it may not have anything to do with that. This time I declared a variable like this:

    Dim item as List(Of MyTestClass)

    When I later used the variable I got the error again. I kept playing around with it when I tried this:

    Dim [item] as List(Of MyTestClass)

    Now the error went away as long as I referred to this variable with [] everywhere. Then I tried it with a different variable name without the [] and it worked fine. Then on a whim I tried "item" again without the []. This time I could not get the error anymore. The previous compile had fixed it somehow even though I now had the exact same code that failed previously.

    So something seems to trigger it intermitently but I have not clue how to reproduce it now.

    Here is another clue. I have a big project (around 10,000 lines of code) targeted for .NET v3.5. When I change the target to .NET v4.0. I get a ton of errors (max number that VS can show) for every variable in my project. "'VariableName' is not declared. It may be inaccessible due to its protection level." When I go back to v3.5 all errors go away.

    I'm starting to wonder if it has to do with the combination of DLL references that I am using. Maybe there is a namespace resolution problem that VS2010 seems to be getting confused when reflecting.

    Monday, May 24, 2010 10:45 AM
  • Hi Perry,

    Thanks for your reply! It's really strange behavior in with []. Does this issue occur in a new VB project, or you tested in your big project? Baded on my research, if the project is coverted from a project written in another language, for example, C#, you may encounter this kind of issue.  If that is the case, please remove all the namespace wrappers as descirbed here.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, May 26, 2010 6:29 AM
  • The error does not occur with a new VB project.

    The project was never converted from C# but was converted many times from previous VB versions: VS2002 --> 2003 --> 2005 --> 2008 -->2010 and it is a rather large project. Never had any problems with any of the other conversions.

    I don't understand what namespace wrappers I should remove. All my classes are indeed encapsulated in their own name spaces but that's normal practice.

    Wednesday, May 26, 2010 1:11 PM
  • Hi Perry,

    When converted from Visual Studio 2008 to VS2010, you could open the project file in VS2010 directly, there will be a convertion wizzard for you to automatically convert the project.

    Besides, since the issue is related to breakpoint, please also try to delete the .suo file before open the .sln file in VS2010 (please backup it if you need it)

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Friday, May 28, 2010 5:02 AM
  • Yes I already converted the project to VS2010. That is when the problem started happening.

    Tried deleting the .suo and did not fix the problem.

    However I have more clues to the problem. My app is targeted at .NET 3.5. If I retarget it at .NET 4.0 the problem goes away. But when I put it back to 3.5 the problem comes back. Must be a versioning bug in the IDE.

    Sunday, May 30, 2010 8:44 AM
  • I was getting this error at compile time after referencing a .Net 3.5 DLL. After I changed the .Net Framework from ".Net Framework 4 Client Profile" to ".Net Framework 4" the problem went away. I am playing with VS2010 and I am using a new console project. The default Framework was the Client Profile one. I don't know which one is set when migrating from a previous version.

    I hope that helps.

    Monday, June 14, 2010 7:29 PM
  • I noticed the same thing that changing the target to .NET 4.0 does solve the problem but I need to stay in v3.5.
    Tuesday, June 15, 2010 6:32 AM
  • I have this Problem also quiet often in VB in VS2010.

    It effects all local variables inside member methods. I have no trouble to explore "Me", or the Method Parameters.

    But all the local variables like

    Dim i As Integer

    appear in watch as "'i' is not declared. It may be inaccessible due to its protection level. "

    It's like the debugging information is missing. I cannot confirm it has anything to do with breakpoints, there is no other way to debug, than with setting a breakpoint, so all you can try is putting the breakpoint more far away from the place to debug, but this had no effect.

    I don't know if it has anything to do with it, but because you were speculating around these topics:

    I have a multilanguage solution C#/VB, auto converted from VS2008, and changed Platform target to .NET 4.0

    Wednesday, June 23, 2010 1:18 PM
  • I have the same problem recently, variables declare at the class level (e.g. Private something as string) is working (I mean pointing the mouse cursor over the variable will show the value of the variable), but variables declared in the Subroutine or Function is just having problem (e.g. Dim something as string).  

    While debugging, pointing the mouse cursor over the variable does not show anything, add the variable to Watch, it will say '<variable> is not declared. It may be inaccessible due to its protection level.', but the program is actually working, only can't see the value of the variable.

    Did a Clean and Rebuild didn't help.

    I am using VS2010 10.0.30319.1 RTMRel

     




    • Edited by Ah Lun Monday, October 24, 2011 7:01 AM
    Monday, October 24, 2011 6:30 AM
  • Still having this problem, this is very troublesome, able to debug the project but not able to see the value of the variables, sigh.

    I was thinking this might be the caching problem in TFS (I am using TFS 2010), cleared the cache, clean the solution, rebuild the solution in debug mode, but didn't solve the problem.

    Please help!!!

    Thanks in advance.


    • Edited by Ah Lun Thursday, November 03, 2011 2:26 AM
    Thursday, November 03, 2011 2:20 AM
  • I tried to execute VB2010 using "Windows XP sp3" compatibility mode property on my windows 7 64bit machine and IT'S WORK!

    Now I can see the content of the variables during the debugging.

    Greetings from Italy

    Thursday, March 29, 2012 10:10 AM
  • today the solution that I suggested isn't working!
    The variables into a form cannot be watched, those in module yes.....

    Downgrade to VS2008?

    Monday, April 02, 2012 9:10 AM
  • Anyone got a solution to this. I can't debug anything with this VS2010 bug.
    Monday, June 18, 2012 1:33 AM
  • I haven't solved the cause of the problem, but I found this useful as a workaround: http://stackoverflow.com/questions/3043881/debugging-with-visual-studio-2010-and-vb-net-immediate-fails-due-to-protection

    I had this problem for ages, and as soon as I did a solution Clean and Rebuild, my debugging started working properly again.

    For what its worth, I find that form and class level variables are fine, as well as any parameters passed into Subs and Functions.  It's only the locally declared variables that I can't access in either the Immediate window or watch lists.

    Tuesday, July 10, 2012 3:22 PM
  • Deleting my .suo and .user file, then cleaning and rebuilding worked for me.
    Wednesday, October 17, 2012 11:51 PM
  • I have a PC with Win7-64 Professional SP1 and VS2008, VS2010 and VS2012.

    As you can see from the two images until the statement "Using" is not executed  you can see the contents of the variable SqlSel, but you just executed the statement "Using" the popup is no longer displayed and also Immediate Window or Watch Windows dispalys the error 'SqlSel' is Not Declared. It may be two inaccessible to its protection level.

    With the release of VS2008 everything works fine (same project, same sub, same PC, etc.)

    Yesterday I installed the VS2012 and surprise, the bug is still here!!!

    Please help

    Wednesday, January 23, 2013 9:39 AM
  • I have a PC with Win7-64 Professional SP1 and VS2008, VS2010 and VS2012.

    As you can see from the two images until the statement "Using" is not executed  you can see the contents of the variable SqlSel, but you just executed the statement "Using" the popup is no longer displayed and also Immediate Window or Watch Windows dispalys the error 'SqlSel' is Not Declared. It may be two inaccessible to its protection level.

    With the release of VS2008 everything works fine (same project, same sub, same PC, etc.)

    Yesterday I installed the VS2012 and surprise, the bug is still here!!!

    Please help

    Wednesday, January 23, 2013 9:42 AM