VS2010: Watching variables is not possible?
I use VS2010 as my vb.net compiler but sometimes I cannot watch a local variable while debugging.
Actually, when I add my local variable to watch window, it says that :
'sm' is not declared. It may be inaccessible due to its protection level.
开发者_运维百科
'sm' is my local variable and has beed declared within my routine.
Here is some my simple code snippet:
Public Sub Calculate()
Dim sm As String
Dim c(2) As Byte
c(0) = 49
c(1) = 85
c(2) = 121
sm = Encrypt_Str(c)
'...
'...
End Sub
Well, I cannot watch 'sm' after the line sm = Encrypt_Str(c)
. What causes this?
What worked for me was going into the project properties, selecting the 'Debug' tab and then ticking the 'Enable the Visual Studio hosting process' box.
if you are using something like
For Dim i as Intenger To something
//Do something
Next i
something() //You are debuging here
The variable wount appear on Watch since it just exists for that block of code. But is only a guess. I could be better if you post some code
I couldn't watch any of my controls / variables.. Cleaned and rebuilded but that didn't help either, I created a new configuration in the configuration manager and copied my debug settings et voila my watch worked like a clock again ;)
Regards,
Mike
I recently had exactly the same issue in Visual Studio 2013. I was debugging VB.NET code in an ASP.NET code behind class. I could break point, step over and into statements, but trying to view / watch a variable would result in that error:
'myvar' is not declared. It may be inaccessible due to its protection level.
What worked for me was:
- Do a clean of the entire solution - so, right click on the solution in the solution explorer window then select Clean Solution.
- Rebuild the solution.
- Run in debug mode - variable can now be viewed / watched.
Happy coding.
精彩评论