none
runtime problem optimize optimization watch 1 window variable "does not exist in the current context"

    General discussion

  • Thanks for your time.
    Visual Studio 2008 on Vista C#
    I have also looked at some similar questions
    I noticed casually but not via intense testing this problem under Vista .. I do not remember this problem under Windows XP
    This is a runtime error NOT a compile time error.
    During runtime I use the IDE to look at variable values (exciting)
    For some variables I see in the watch 1 window of the ide
    "does not exist in the current context"
    and the variable name does not appear the locals window
    I have attempted to turn off optimization .. this attempt fails for me and the undesired situation persists
    It has been stated elsewhere that optimization can make some variables unnecessary
    On the menus of VS2008 I navigated
    Project <> Application Name Properties <> Build <> Optimize Code
    The check and uncheck occurs .. without a successful affect.
    (Is there an elaborate way to check and uncheck this option???)

    Summary
    Desired Situation
    To see all variable in the local variables window and the watch 1 window
    +++++++++++++++++++++++++++++++++++++++++++++++++
    Actual Failed Situation
    Some variable names are not available for inspection even with Optimization turned OFF

    Thanks in advance for your comments
    • Changed type Roahn Luo Monday, November 23, 2009 5:20 AM OP does not follow up.
    Sunday, November 15, 2009 9:34 PM

All replies

  • Hello,

    Thanks for your post!

    Are all the variables we want to see in the current call stack? I ask this because the Locals/Watch windows only displays variables of the current call stack (we could view it from the Call Stack window). If we want to view variables accross call stacks, I would recommend you use Object ID.

    Besides, there are many alternative ways to view variables:
     1. using Inmediate window
     2. using DataTips, hovering our mouse on the variable name, its value will be displayed automatically in the Datatips.
    Can any of these workarounds work for you?

    Please let me know if this helps,
    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!
    Monday, November 16, 2009 6:42 AM
  • Thanks for replying .
    You mentioned the word workaround. ... Are you implying this is a known problem?
     .. if so ..
    ??? In what context???  Is Vista the context?  I have one machine which is Vista.
    My previous machine was Windows XP ... it apparently has a hardware crash.

    The datatips for these same problem variables are ABSENT.
    When I uncheck the Optimize check box .. there is no save button ... I rebuild the solution.
    Is that a reasonable course of action?
    I rarely use the immediate window.
    I can research the immediate window ... though I will take an example if you have one.
    I suppose the lowest of all workarounds is the Console.Writeln strategy which I did use.




    Monday, November 16, 2009 7:28 AM

  • I believe I am trying to observe all local variables created in the same function and in scope.
    ++++++++++++

    if (y_bq >= 0 && y_bq < rq.Height)
    {
    byte* pyk = (byte*)Scan2 + (stride * y_bq);
    //
    //scan2 and stride are observable in debugger
    //pyk and y_bq are not observable in the debugger 
    
    //breakpoint hit in next line ... so all the varbiables in the above line 
    //are candidate for observation
    
    for (int x_bq = rfill_center_pos.Left; x_bq < rfill_center_pos.Right; ++x_bq)
    



    Monday, November 16, 2009 8:03 AM
  • You mentioned the word workaround. ... Are you implying this is a known problem?
     .. if so ..
    ??? In what context???  Is Vista the context?  I have one machine which is Vista.
    My previous machine was Windows XP ... it apparently has a hardware crash.

    The datatips for these same problem variables are ABSENT.
    When I uncheck the Optimize check box .. there is no save button ... I rebuild the solution.
    Is that a reasonable course of action?
    Hello,

    Thanks for your reply and detailed code snippet, we really appreciate it. I'm sorry if I'm not so clear but I didn't think I mentioned a "word workaround".
    To bring back the save button, please go to Tools -> Customize -> Toolbars tab, and check Standard checkbox, or, we could use Ctrl + S shortcut keys to save the changes. Please make sure we clear the Optimize code option.

    For further discussion, please explain the code snippet in more detail. This is because, in some scenarios, Visual Studio could not show us the detail information about the local variables, please see the link below for more information:
    http://blogs.msdn.com/habibh/archive/2009/09/22/debugging-a-com-object-runtime-callable-wrapper-with-visual-studio-2010.aspx

    I also encourage you to evaluate the issue with Visual Studio 2010, if it still has any issue, please send us your feedback.
    Thanks a lot!
    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!
    Monday, November 16, 2009 11:25 AM
  • Thank You
    However,
    I am not using a com object.
    So the article does not seem to apply to this discussion.
    The scenario does not apply to my question.
    Monday, November 16, 2009 9:33 PM
  • Hello,

    Thanks for your feedback. Well, could you please post the code snippet of the *stride* type? In my test project, I used a code snippet as below:
            static void Main(string[] args)
            {
                unsafe
                {
                    int result = 0;

                    int m1 = int.MaxValue;
                    int m2 = int.MaxValue;

                    int* max1 = &m1;
                    int* max2 = &m2;

                    result = *max2 + *max1;

                    Console.WriteLine("The values is " + result);
                }
             }
    If we use this code snippet, how about the issue?

    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!
    Tuesday, November 17, 2009 2:21 AM