ToString() does not exist ... anywhere !

J

John A Grandy

In .NET v1.1.4322 , in a VS.NET application , has anyone ever run into the
bizarre situation where at runtime .NET believes that the ToString() method
does not exist ...

Sometimes this problem will show up as a runtime exceptions, sometimes this
problem will only be clear via QuickWatch in Debug mode

But the error message is always identical :

"error: '{object name}.ToString' does not exist:"

It could be

System.Data.SqlConnection.SqlClient.State.ToString()

or it could be

Application["key name"].ToString()

or a variety of other uses of the ToString() method ...

I've tried rebuilding , restarting the machine ... but the problem
continues.

This is the strangest behavior I have ever encountered
 
F

Fabio

"John A Grandy" <johnagrandy-at-yahoo-dot-com> ha scritto nel messaggio


"error: '{object name}.ToString' does not exist:"

It could be

System.Data.SqlConnection.SqlClient.State.ToString()

or it could be

Application["key name"].ToString()

or a variety of other uses of the ToString() method ...

I've tried rebuilding , restarting the machine ... but the problem
continues.

Can't you debug this?
 
B

Bill Butler

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
But the error message is always identical :

"error: '{object name}.ToString' does not exist:"

Quick checklist
Typo?
Did you remember the parens?

Bill
 
M

Marc Gravell

Well, neither of the 2 lines you are showing look valid to me; the first has
the namespace knackered, and doesn't seem to involve an instance; the second
(assuming System.Windows.Forms.Application) simply doesn't have a static
indexer.

QuickWatch will allow these as lines, but they will report error - simply
because they don't exist; I'd be more interested in the runtime exceptions,
as I don't think that code can compile.

Are you sure the problem isn't the code? Perhaps calling .ToString() on some
null objects? If you can get as far as runtime, then (assuming it isn't
reflection) it knows it exists. Have you overridden the ToString() method
and screwed it up, perhaps?

Marc
 
J

John A Grandy

Ok, this is a production project that was working fine. It somehow
"entered" a state where somehow .NET is reporting that the .ToString()
method does not exist on various classes.

ToString() is not overriden anywhere in the project.

There was a typo: I meant

System.Data.SqlClient.SqlConnection con = new
System.Data.SqlClient.SqlConnection();
con.State.ToString();

QuickWatch on con.State.ToString() gives the error "error: '{object
name}.ToString' does not exist:"

Also, this is an ASP.NET app , so the intrinsic Application object is an
instance of the HttpApplicationState class

QuickWatch can be performed on Application[{key-name}] with no problem.

But QuickWatch on Application[{key-name}].ToString() gives the errror
"error: '{object name}.ToString' does not exist:"
 
J

John A Grandy

I've never had to override ToString() before ... ever. I've seen the source
for dozens of high quality projects, and none of them includes overrides of
intrinsic ToString() methods on .NET framework classes.

Project was in a working state before -- it never threw any of these
exceptions.
 
P

poojo hackma

I've never had to override ToString() before ... ever. I've seen the
source for dozens of high quality projects, and none of them includes
overrides of intrinsic ToString() methods on .NET framework classes.

Project was in a working state before -- it never threw any of these
exceptions.

I'm not 100%, but I think overriding ToString() started with VS 2005. Not
sure why some other things still work with ToString(); maybe they inherit
something else that has a built in version, but that's just a guess.
 
J

John A Grandy

I'm on VS03 with .NET 1.1

poojo hackma said:
I'm not 100%, but I think overriding ToString() started with VS 2005. Not
sure why some other things still work with ToString(); maybe they inherit
something else that has a built in version, but that's just a guess.
 
M

Markus Stoeger

John said:
I've never had to override ToString() before ... ever. I've seen the source
for dozens of high quality projects, and none of them includes overrides of
intrinsic ToString() methods on .NET framework classes.

Project was in a working state before -- it never threw any of these
exceptions.

Which exceptions? (type, message, stacktrace, code snippets please!)

QuickWatch sometimes does silly things. But it would be interesting to
see these exceptions and the code that generates them.

Max
 
J

John A Grandy

Well, as I mentioned above, it's things like :

using System.Data.SqlClient;

SqlConnection sqlConnection = new
SqlConnection("server=SERVER1;database=DB1;TRUSTED_CONNECTION=true");
sqlConnection.Open();
if (sqlConnection.State.ToString() = "open")
{
....
....
}

If I QuickWatch over sqlConnection.State.ToString() I receive

"error: '{object name}.ToString' does not exist:"
 
S

Sericinus hunter

Is there any particular reason not to use enumeration?

if(sqlConnection.State == ConnectionState.Open)
{
....
}
 
J

John A Grandy

This isn't a code-design exercise. This is a huge project written by
someone else. They already used .ToString() in thousands of places,
thousands of contexts. Somehow, ToString has stopped being recognized.

I've tried de-installing, re-installing .NET Framework 1.1.4322 , to no
avail.
 
M

Markus Stoeger

John said:
If I QuickWatch over sqlConnection.State.ToString() I receive

"error: '{object name}.ToString' does not exist:"

You can't use the Watch window on methods. It only works for fields and
properties (at least in VS2003, dunno about VS2005).

If you get real (runtime) exceptions, please post their type, message
and stacktrace.

Max
 
C

Conor O' Driscoll

Hi, Just wondering if you found the answer to the .Tostring problem,
Currently i am having the same problem.
If i try the same code in vb instead of c# it works fine. Appear to be
affecting c# only.
 
D

D W

I'd love to see an answer posted for this issue too. I'm having the
exact same problem in VS2003.

Here's the line:

cmd.Parameters.Add("@DestDB", newCompany.ToString() + RequestYear);

It's a very simple concat that's been working since before I started
with this company. In fact, it was working about an hour ago. The
project compiles, and I even get a "ToString" option from Intellisense,
but I still get the not recognized error at runtime.

"newCompany" is an enum type that has a verifiable value before trying
to execute this line. "RequestYear" is a string representing a 4 digit
year.
 
J

Jon Skeet [C# MVP]

I'd love to see an answer posted for this issue too. I'm having the
exact same problem in VS2003.

Here's the line:

cmd.Parameters.Add("@DestDB", newCompany.ToString() + RequestYear);

It's a very simple concat that's been working since before I started
with this company. In fact, it was working about an hour ago. The
project compiles, and I even get a "ToString" option from Intellisense,
but I still get the not recognized error at runtime.

"newCompany" is an enum type that has a verifiable value before trying
to execute this line. "RequestYear" is a string representing a 4 digit
year.

What error do you get at runtime *not* in the debugger? I suggest we
ignore the debugger for the moment, as the VS2003 debugger in
particular had some issues.

Jon
 
D

D W

I replied to this a while ago, but don't see it here now.

To reiterate:

I was having other runtime issues not involving this one, so I can't say
that it was strictly a debugger issue...though I believe that it was.

Here's what I did instead that worked:

string Company = System.Convert.ToString(newCompany);
string Year = System.Convert.ToString(RequestYear);

cmd.Parameters.Add("@DestDB", System.String.Concat(Company + Year));
 
J

Jon Skeet [C# MVP]

D W said:
I replied to this a while ago, but don't see it here now.

To reiterate:

I was having other runtime issues not involving this one, so I can't say
that it was strictly a debugger issue...though I believe that it was.

Here's what I did instead that worked:

string Company = System.Convert.ToString(newCompany);
string Year = System.Convert.ToString(RequestYear);

cmd.Parameters.Add("@DestDB", System.String.Concat(Company + Year));

There's really no reason that should work but the "normal" way
wouldn't. I strongly suspect it was just a debugger issue.
 

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