formatting Error

So why do I get this error with the same code (newRow = Cp.tostring("n4")) in one class and not in another? The error being: Unable to cast object of type System.string to type System.IFormatProvider. Same imports, same required references...
[252 byte] By [etcheverrjc] at [2007-12-28]
# 1

What are the types of "newRow" and "Cp"?

Also, can you provide the call stack from the exception?

-Scott Wisniewski

ScottWisniewski-MSFT at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
Try turning Option Strict to On in both cases - Most conversion errors can be caught by the compiler when Option Strict is On.
ShyamN at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

etcheverrjc,

IFormatProvider provides a mechanism for retrieving an object to control formatting. Formatting methods convert the value of a type to the string representation of that value Parsing methods convert the string representation of a value to a type with that value. These methods use the GetFormat method of types that implement the IFormatProvider interface to obtain an object that supplies information used in the formatting or parsing operation. The IFormatProvider interface places no requirements or restrictions on the information that is supplied.

It seems that you are not familiar with the IFormatProvider interface and please have a look at the following link with an example sample code on the GetFormat method as follows:

http://msdn2.microsoft.com/en-us/library/system.iformatprovider.aspx

Hope that will help you :-)

BrunoYu-MSFT at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

Bruno, to be honest, I really don't know what you mean. I looked at the link you provided while I see how it is linked with what I am doing, I don't see how it would be the source of my problem in this case... I literally used the same line of code on two different lines, with only the variable changing, same type though, and received this exception. Is there something in the link you provided that I'm missing? Anyway, in midst of my coding, somewhere along the way a mysterious change has occured, and I can no longer reproduce the exception. Normally I would find this satisfying, but I don't like not knowing why it wasn't working, so any thoughts on the matter would still be appreciated...

John

etcheverrjc at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5
Every class uses its own overloads for the Object.ToString() method. For example, the System.Boolean type has the ToString(IFormatProvider) overload but no ToString(String) overload. It depends on the type of your "Cp" variable.
nobugz at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6
Double. Both of them were doubles.
etcheverrjc at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...