开发者

Debugging with Visual Studio 2010 and VB.NET: Immediate fails due to protection level

It happens quite frequently, more times per day, that with Visual Studio 2010, during the debugging, when I used Immediate commands like:

? NamedVariable

I receive the following error:

'NamedVariable' is not declared. It may be inaccessible due to its protection level.

In this case also other debug features seems gone, but I can set breakpoints, step into, step over, etc.

The solution is stop debugging, clean and rebuild the project, and retr开发者_如何学编程y.

I am developing a VB.NET Windows Forms application, but it happened with VB.NET WPF projects too. I never had this behavior with VS 2008.

Is this a known bug or could it be a problem of my environment/installation? Do you have any idea how to solve this little, but annoying issue?


This happens quite often to me, too. And the only solution I found out up to now is:

The solution is stop debugging, clean and rebuild the project, and retry.

Deleting the suo file will not help. And it can happen anywhere in the code and does not seem to be depending on the code itself.

I think this is happening mostly after I modified some code during debugging or after a lot of minor changes and builds before the debugging. Maybe the debugging information gets "lost" or "unsynrconised" during some partial build process.

I think its a VisualStudio bug and that it will be fixed in a hopefully soon ServicePack.


Try, making sure the code file that contains the variable is displayed and the cursor is within the same scope of the variable.

Try, deleting the solution's user options file (suo). You will lose your settings, such as bookmarks, breakpoints, and other user solution settings.


Note also this will tend to occur inside some "With variable ..." blocks of code.

In this case replace the "With variable" with a temporary variable and the issue may clear.


I ran into this in one of my classes and it seemed to be only in one method within the class.

I tried...

  • Cleaning & rebuilding
  • Deleting the suo file
  • Recreating the offensive class file
  • Repairing Visual Studio (2010 SP1)

None of this helped.

Neither of the two projects involved used the Client Profile version of the 4.0 .NET Framework.

What worked for me, which I found by accident, was when I was stepping through another method, that called the offending method. When I stepped into that method, I could see my variables again via the watch window, immediate window, etc.

Not sure why this happened, I think it's just a bug, but this worked for me, so I thought I would pass it along.


I couldn't watch any of my controls / variables.. First time creating a new configuration did the trick but 'today' I had the same problem, drove me crazy for hours.. It all boils down to 'Debug - Windows - Modules' Check if the right pdb file / pdb file location is loaded, mine was refering to a obfuscated folder and I suspect that being the reason I couldn't watch / view the props and vars.. I right clicked the problem line and tried to direct it to the right folder / pdb file but then I got: A matching symbol file was not found in this folder

I deleted all build folders in the explorer, rebuild and pointed my XAP file 'Debug - Windows - Modules - Load symbols' to the right pdb file...

Regards,

Mike


Just thought I add my 2 cents. I experienced this with 2012 debugging a lambda. Take this simple example.

    Dim A As String = "A"
    Dim B As String = "B"

    Dim Test = Function(C As String) As String
                   Return C & A
               End Function

    Debug.Print(Test("Test "))

Putting a breakpoint on the Return C & A statement, you would expect that you could examine B as it is in scope inside the closure. But trying this in the immediate window, you'll get the 'B' is not declared. It may be inaccessible due to its protection level, error. The reason is because it's not being used in the Test function. You need to actually use the variable somewhere inside the test function to be able to see it while debugging.


I also had the same problem. I'm trying to test a sub routine in the immediate window and kept getting this error.

One solution is to:

For VS 2008 (may work with other versions)

  1. Open VS exe file, by right clicking and running as Administrator

  2. Once VS is opened go to your solution file, load it and then right click on the project name and select 'properties'

  3. Go to the 'Debug' tab

  4. Uncheck 'Enable the visual studio hosting process'

  5. test your sub routine in immediate window

second solution is to:

  1. Clean the project

  2. Close down

  3. Reboot PC

  4. Re-open and 'Run as Administrator'

  5. Go to 'My Project' in Solutions window

  6. Click on 'Debug'

  7. Tick the option 'Enable native code debugging' (if you have another version of VS then look here Enable Debugging)

  8. Retest sub routine in immediate window and then close and re-open project

  9. Repeat steps 5 and 6 but this time untick 'Enable native code debugging'

  10. Rebuild solution

And poof by magic somehow its now started working.


This problem is related to the definition of object in the <formname>.aspx.desginer.vb (where <formname> is the name of your form). To correct this try...

On the solution explorer tab found on the right hand side, click the 2nd button (show all files). Go down to the and expand it to see the subfiles. There should be a <formname>.aspx.desginer.vb. Open the <formname>.aspx.desginer.vb and you will see the definition for all the form object such as Protected WithEvents submitButton As Global.System.Web.UI.WebControls.Button. Add a definition for your object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜