Why does tsSource[j].Text.ToUpper() causes side effects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Academia

    Why does tsSource[j].Text.ToUpper() causes side effects

    I get the following watch message:

    tsSource[j].Text.ToUpper() This expression causes side effects and will
    not be evaluated string


    The Text is &Edit



    Do you know what are the side effects?



    Thanks


  • Gilles Kohl [MVP]

    #2
    Re: Why does tsSource[j].Text.ToUpper() causes side effects

    On Sun, 16 Mar 2008 02:45:41 -0400, "Academia" <academiaNOSPAM @a-znet.com>
    wrote:
    >I get the following watch message:
    >
    tsSource[j].Text.ToUpper() This expression causes side effects and will
    >not be evaluated string
    >
    >
    >The Text is &Edit
    >
    >
    >
    >Do you know what are the side effects?
    There probably aren't any in this case, but the debugger is not smart enough
    to be able to tell - so it prefers to err on the safe side.

    Quoting from http://msdn2.microsoft.com/en-us/library/a7a250bs.aspx :

    "A side effect occurs when evaluating an expression changes the value of data
    in your application.

    Side effects are something to watch for if you are evaluating expressions in
    the debugger. If you evaluate an expression in the Watch window or the
    QuickWatch dialog box and the expression has side effects, you might change
    the value of variables in another part of your program without realizing it.
    Side effects can make debugging more difficult by creating the appearance of
    bugs where none exist or masking the appearance of real bugs.

    One common cause of side effects is evaluating a function call in a debugger
    window. Such evaluations are usually noticeable. A more subtle cause of side
    effects is the evaluation of properties and other implicit function calls in
    managed code.

    The debugger cannot tell whether a property evaluation or implicit function
    call has side effects. Therefore, by default, the debugger does not evaluate
    implicit function calls automatically. Property evaluation is allowed by
    default, but can be turned off in the Options dialog box. When a function call
    or property has not been evaluated, a refresh icon appears. You can manually
    evaluate the expression by clicking the refresh icon. For details, see How to:
    Refresh Watch Values."

    Regards,
    Gilles.



    Comment

    • Academia

      #3
      Re: Why does tsSource[j].Text.ToUpper() causes side effects

      Thanks for the help

      "Gilles Kohl [MVP]" <no_email_avail able@wrote in message
      news:9ohpt3pd1q irvss8011pvir4g 0eh85ccsa@4ax.c om...
      On Sun, 16 Mar 2008 02:45:41 -0400, "Academia" <academiaNOSPAM @a-znet.com>
      wrote:
      >
      >>I get the following watch message:
      >>
      > tsSource[j].Text.ToUpper() This expression causes side effects and will
      >>not be evaluated string
      >>
      >>
      >>The Text is &Edit
      >>
      >>
      >>
      >>Do you know what are the side effects?
      >
      There probably aren't any in this case, but the debugger is not smart
      enough
      to be able to tell - so it prefers to err on the safe side.
      >
      Quoting from http://msdn2.microsoft.com/en-us/library/a7a250bs.aspx :
      >
      "A side effect occurs when evaluating an expression changes the value of
      data
      in your application.
      >
      Side effects are something to watch for if you are evaluating expressions
      in
      the debugger. If you evaluate an expression in the Watch window or the
      QuickWatch dialog box and the expression has side effects, you might
      change
      the value of variables in another part of your program without realizing
      it.
      Side effects can make debugging more difficult by creating the appearance
      of
      bugs where none exist or masking the appearance of real bugs.
      >
      One common cause of side effects is evaluating a function call in a
      debugger
      window. Such evaluations are usually noticeable. A more subtle cause of
      side
      effects is the evaluation of properties and other implicit function calls
      in
      managed code.
      >
      The debugger cannot tell whether a property evaluation or implicit
      function
      call has side effects. Therefore, by default, the debugger does not
      evaluate
      implicit function calls automatically. Property evaluation is allowed by
      default, but can be turned off in the Options dialog box. When a function
      call
      or property has not been evaluated, a refresh icon appears. You can
      manually
      evaluate the expression by clicking the refresh icon. For details, see How
      to:
      Refresh Watch Values."
      >
      Regards,
      Gilles.
      >
      >
      >

      Comment

      • Ben Voigt [C++ MVP]

        #4
        Re: Why does tsSource[j].Text.ToUpper() causes side effects

        Academia wrote:
        I get the following watch message:
        >
        tsSource[j].Text.ToUpper() This expression causes side effects and
        will not be evaluated string
        I rather suspect the message is "This expression causes no side effects".

        What you've asked for is:
        Find the jth item.
        Read it's Text property.
        Make an uppercase copy.
        Throw away the result.


        Comment

        • Peter Duniho

          #5
          Re: Why does tsSource[j].Text.ToUpper() causes side effects

          On Tue, 18 Mar 2008 09:02:26 -0700, Ben Voigt [C++ MVP]
          <rbv@nospam.nos pamwrote:
          Academia wrote:
          >I get the following watch message:
          >>
          > tsSource[j].Text.ToUpper() This expression causes side effects and
          >will not be evaluated string
          >
          I rather suspect the message is "This expression causes no side effects".
          >
          What you've asked for is:
          Find the jth item.
          Read it's Text property.
          Make an uppercase copy.
          Throw away the result.
          "Watch message" implies debugger. What you're describing would be a
          problem if the compiler were looking at the expression, but here the
          result of the expression isn't thrown away, it's (in theory) displayed to
          the user.

          In practice, it seems that it's not being displayed, because the debugger
          believes it causes side-effects and thus won't evaluate it. Why that
          should be, I don't know...I can't reproduce the same problem (my debugger
          seems perfectly happy to put a call to ToUpper() in the watch window, even
          when the source is some variable or property). But it's not hard to
          believe that the debugger is hesitate to call a method in the watch window
          because of the possibility of a side-effect.

          Pete

          Comment

          Working...