Trouble with Identically-Named Variables

R

Robert Thompson

Hello,

I'm running into a strange problem involving identically-named
variables in multiple projects. I'm using Visual Studio 2005, and have
a solution with three projects under it. Two of the three projects
have variables with the same name. These variables are both global to
their class. The problem is that when variable "foo" in Project 1 is
set to "bar," variable foo in Project 2 also immediately takes on value
bar. This occurs regardless of whether foo is references simply as
foo, or as this.foo.

I can't figure out how this is occuring, as the projects do not contain
references to each other (they are completely independent projects),
but the debugger shows that this is the case and when running without
debugging I get strange behavior that I suspect is caused by this.
It's a simple matter to rename one project's variable for now, but I
would like a more permanent solution.

Thanks for your help!
 
M

Michael C

Robert Thompson said:
I can't figure out how this is occuring, as the projects do not contain
references to each other (they are completely independent projects),
but the debugger shows that this is the case and when running without
debugging I get strange behavior that I suspect is caused by this.
It's a simple matter to rename one project's variable for now, but I
would like a more permanent solution.

Does renaming help? Are you using any of the variables in API calls? Are
these 2 projects running in the same process?

Michael
 
J

Jon Skeet [C# MVP]

Robert said:
I'm running into a strange problem involving identically-named
variables in multiple projects. I'm using Visual Studio 2005, and have
a solution with three projects under it. Two of the three projects
have variables with the same name. These variables are both global to
their class. The problem is that when variable "foo" in Project 1 is
set to "bar," variable foo in Project 2 also immediately takes on value
bar. This occurs regardless of whether foo is references simply as
foo, or as this.foo.

I can't figure out how this is occuring, as the projects do not contain
references to each other (they are completely independent projects),
but the debugger shows that this is the case and when running without
debugging I get strange behavior that I suspect is caused by this.
It's a simple matter to rename one project's variable for now, but I
would like a more permanent solution.

It sounds unlikely to be happening as you have described - I suspect
you have debugger issues.

As Mark said, if you could post a short but complete program which
demonstrates the problem, that would help enormously.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top