Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 06, 2016, 03:51:12 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: C# & Visual Studio Problem  (Read 6540 times)

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
C# & Visual Studio Problem
« on: January 15, 2011, 05:20:27 AM »
Sigh... Yes... I've searched... And I can't find the answer... This is bizarre. (I bet $10 somebody will find the answer real easy now...)

Anyways, check this screenshot:

Screenshot - 2011-01-15 , 10_06_25 PM.pngC# & Visual Studio Problem

My problem is that all of a sudden, I can't "mouse over" to find variable values when debugging.

You can see in there that "comparisons" has values in it, however, "singleComparison" shows "...does not exist in the current context." Huh? It's populating "comparisons", so it obviously has values in it, but...

Similarly, pi1, pi2 and pis won't show any values there. They don't exist~! But they do~!

See how bizarre this is?

Does anyone have any idea how to fix this?
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,779
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #1 on: January 15, 2011, 07:30:42 AM »
You have compiled in Debug mode, I presume? Try a Clean and Build on the project/solution.
Is it targeting .NET 4 or a lower version?
And pressing the refresh buttons doesn't make a difference?
Any plug-ins messing up VS (2010 I guess?), try to disable 'm one by one to find the culprit. Or reboot your PC, or at least restart VS (but I expect you did that already).

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #2 on: January 15, 2011, 08:01:58 AM »
In debug. Cleaned. Restarted VS. No luck.

Haven't rebooted. I'll need to do that later though.

I have a couple community edition plugins, but they've never acted up before, and they've been in there for quite a while.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

housetier

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 1,321
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #3 on: January 15, 2011, 09:09:28 AM »
Where is your breakpoint? That is, did the uhm.. control flow pass by those statements, or did you break before?

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #4 on: January 15, 2011, 09:26:13 AM »
The break point is at 699. I cut out other stuff below for clarity.

But even when I break on other lines, I get jack. It's very odd.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #5 on: January 15, 2011, 09:58:07 AM »
What's the context of the code?
Are you using the variables at a later point?
Are stuff like PhotoInfo value or reference types?

.NET can do some pretty funky stuff - objects can get garbage collected as soon as it's deemed their lifetime is over, and said lifetime has nothing to do with C/C++ style scope. Stack slots for value types can be reused as soon an object lifetime is over.
- carpe noctem

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #6 on: January 15, 2011, 10:06:38 AM »
When you are stepping through the code at line 690 are pi1 and pi2 available then?

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #7 on: January 15, 2011, 06:35:39 PM »
When you are stepping through the code at line 690 are pi1 and pi2 available then?

No. That's the thing During the entire block there, they are not available. However, they have values...
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #8 on: January 15, 2011, 07:09:31 PM »
What about in the immediate window?  Can you access them there?

Another idea... also to try after that one... if you use the objects right after (i.e. debug.print(pi1.tostring()) or something like that) does it then become accessible?
« Last Edit: January 15, 2011, 07:21:29 PM by wraith808 »

mwb1100

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,522
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #9 on: January 15, 2011, 09:28:51 PM »
Does it happen just for this project or does it also happen if you create a new, simple project?

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #10 on: January 15, 2011, 09:54:17 PM »
It's just that section of code. Other sections (that I checked) seem fine.

So, I tried this...

I had that code arranged like this:

Code: C# [Select]
  1. if (false)
  2. {
  3.   // old stuff
  4. }
  5. else
  6. {
  7.   // all the code was here... (new stuff I'm testing)
  8. }
  9.  
  10. // I moved it all here...

WTF? It's normal again...

Has anyone heard of this kind of wonkiness before?
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #11 on: January 15, 2011, 10:04:19 PM »
what was the condition in the if statement?

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #12 on: January 15, 2011, 10:05:41 PM »
what was the condition in the if statement?
false? :)
- carpe noctem

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #13 on: January 15, 2011, 10:06:04 PM »
what was the condition in the if statement?

Yes. Exactly that. "false". I was using the conditional to toggle old and new refactored code.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #14 on: January 15, 2011, 10:07:40 PM »
Could you try flipping it around so the new code goes in an "if(true)" and see if it affects things? Seems pretty queer to me.
- carpe noctem

mwb1100

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,522
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #15 on: January 15, 2011, 10:30:14 PM »
Has anyone heard of this kind of wonkiness before?

By some coincidence, I was just looking at a bug report for C++ that indicates the debugger has trouble 'finding' variables declared in an `else` clause (at least sometimes):

  - https://connect.micr...t-see-some-variables

I have no idea what extent the debugger for C# uses same or similar code to the debugger for C++, and even if I did I'm not sure how this factoid would help you.  But I posted it anyway, just because it seems similar.
« Last Edit: January 15, 2011, 10:32:48 PM by mwb1100 »

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #16 on: January 15, 2011, 11:31:20 PM »
Has anyone heard of this kind of wonkiness before?

By some coincidence, I was just looking at a bug report for C++ that indicates the debugger has trouble 'finding' variables declared in an `else` clause (at least sometimes):

  - https://connect.micr...t-see-some-variables

I have no idea what extent the debugger for C# uses same or similar code to the debugger for C++, and even if I did I'm not sure how this factoid would help you.  But I posted it anyway, just because it seems similar.

Thanks for that. It seems that it is the exact same issue. The workaround is to define the local variables outside of the conditional.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #17 on: January 16, 2011, 12:47:44 AM »
what was the condition in the if statement?
false? :)


I didn't want to assume... :P  He could have just been doing pseudo code like the rest of the code :)

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #18 on: January 16, 2011, 01:14:52 AM »
what was the condition in the if statement?
false? :)


I didn't want to assume... :P  He could have just been doing pseudo code like the rest of the code :)

Quite correct, and indeed, it is THE crucial point.

what was the condition in the if statement?
false? :)


I didn't want to assume... :P  He could have just been doing pseudo code like the rest of the code :)

Quite correct, and indeed, it's is THE crucial point.

"comparisonIndex" is an Int32 counter that I initialize outside the conditional to -1. It is only ever incremented, so the following will only ever evaluate to false:

Code: C# [Select]
  1. if (comparisonIndex < -111)


Stuff works then.

In short, in C++ or C# (and possibly all other .NET languages or in VS 2010 or something like that), you CANNOT use (literally, and not pseudo-coded-ly ;) ):

Code: C# [Select]
  1. if (false)

And then follow with an else clause.

Instead, use an expression that you KNOW will always evaluate to false.

Bizarre. Yes. Easy to get around once you know. Sure. Sane? Hell no~!
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #19 on: January 16, 2011, 02:14:28 AM »
I just posted a short write-up of the problem and work around here:

if (false) { behave nice; } else { freak out; }

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,779
    • View Profile
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #20 on: January 16, 2011, 05:40:18 AM »
Ugh, what a nasty VS bug >:(. Glad you caught it, I guess I can help some ppl with that! :up:

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #21 on: January 16, 2011, 07:32:23 AM »
In short, in C++ or C# (and possibly all other .NET languages or in VS 2010 or something like that), you CANNOT use (literally, and not pseudo-coded-ly ;) ):
You can't?

Code: C# [Select]
  1. namespace Flaf {
  2.         using System;
  3.         class Program {
  4.                 static void Main(string[] args) {
  5.                         if(false)
  6.                                 Console.WriteLine("The universe implodes");
  7.                         else
  8.                                 Console.WriteLine("Everything's normal");
  9.                 }
  10.         }
  11. }

Quote
E:\temp>csc test.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.

test.cs(6,5): warning CS0162: Unreachable code detected

For the C++ version, I don't even get a warning until I crank up the warning level to /W4... and the warning I get is "test.cpp(5) : warning C4127: conditional expression is constant", not unreachable code :)

Btw, C# allows you to use #if/#else/#endif pragmas (iirc it was included in C# 2), might want to use that instead?
- carpe noctem

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #22 on: January 16, 2011, 07:51:29 AM »
In short, in C++ or C# (and possibly all other .NET languages or in VS 2010 or something like that), you CANNOT use (literally, and not pseudo-coded-ly ;) ):
You can't?

Code: C# [Select]
  1. namespace Flaf {
  2.         using System;
  3.         class Program {
  4.                 static void Main(string[] args) {
  5.                         if(false)
  6.                                 Console.WriteLine("The universe implodes");
  7.                         else
  8.                                 Console.WriteLine("Everything's normal");
  9.                 }
  10.         }
  11. }

Quote
E:\temp>csc test.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.

test.cs(6,5): warning CS0162: Unreachable code detected

For the C++ version, I don't even get a warning until I crank up the warning level to /W4... and the warning I get is "test.cpp(5) : warning C4127: conditional expression is constant", not unreachable code :)

Btw, C# allows you to use #if/#else/#endif pragmas (iirc it was included in C# 2), might want to use that instead?

Your example there doesn't use any local variables declared in the else clause. While it "works", you can't debug it properly as the values aren't available.

The problem is that variables declared inside else clauses (where the first if conditional is literally "false" as opposed to evaluating to false) are not available during debugging. "The name 'blah' does not exist in the current context."

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #23 on: January 16, 2011, 08:17:12 AM »
Your example there doesn't use any local variables declared in the else clause. While it "works", you can't debug it properly as the values aren't available.
Yeah, that's what this whole thread is about, right? :)

I thought your "In short, in C++ or C# (and possibly all other .NET languages or in VS 2010 or something like that), you CANNOT use" mean that the compiler forbids it, like Java forbids unreachable code (C# just warns about it).
- carpe noctem

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: C# & Visual Studio Problem
« Reply #24 on: January 16, 2011, 09:18:19 AM »
Your example there doesn't use any local variables declared in the else clause. While it "works", you can't debug it properly as the values aren't available.
Yeah, that's what this whole thread is about, right? :)

I thought your "In short, in C++ or C# (and possibly all other .NET languages or in VS 2010 or something like that), you CANNOT use" mean that the compiler forbids it, like Java forbids unreachable code (C# just warns about it).

Oh - no. I didn't mean that. I just meant "CANNOT" in the sense of futility and keeping your sanity. :)

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker