1

I run my C# application which is big so I just included a part of the code

My code:

allowGift = Convert.ToInt32(dRow[14]) == 1;
allowInventoryStack = Convert.ToInt32(dRow[15]) == 1;
interactionType = InterractionTypes.GetTypeFromString((string)dRow[16]); //Line of error

And the error of stack trace

System.InvalidCastException: Unable to cast object of typpe 'System.Boolean' to type 'System.String'

3
  • 1
    What is the type of dRow? And what is the type of interactionType? and what line is causing the error? Commented Jan 12, 2014 at 21:33
  • 2
    You seem to be using this class. While most of the answers below are well-intentioned, they won't work, as InteractionType has no conversion from True or False. I'm sorry to say that your question is not answerable, from the information you've given us. Commented Jan 12, 2014 at 21:39
  • Look at the InteractionType enum (which includes values such as "football", "teleport", and "firegate"), and make sure that the values you're passing to GetTypeFromString are in there. Commented Jan 12, 2014 at 21:43

4 Answers 4

2

Instead of this:

(string)dRow[16]

Try ToString:

dRow[16].ToString()

Or Convert.ToString :

Convert.ToString(dRow[16])
Sign up to request clarification or add additional context in comments.

Comments

1

Change this line:

interactionType = InterractionTypes.GetTypeFromString((string)dRow[16]); //Line of error

to this:

interactionType = InterractionTypes.GetTypeFromString(dRow[16].ToString()); //Line of error

2 Comments

Unkown interaction type in parse code: False System.InvalidCastException: Specified cast is not valid
Please look at @Michael Petrotta comments for your question. This error is not relevant to your question, which was how to convert Boolean to String. This error is due to the use of that InterractionTypes library that you are using, which does no accept False as a valid input value.
1

A bool cannot be directly cast to a string it needs to be converted. You can just use the Converter class as you've done elsewhere in the code

InterractionTypes.GetTypeFromString(Convert.ToString(dRow[16]));

Comments

0

Instead of (string)dRow[16] Use dRow[16].ToString()

1 Comment

Unkown interaction type in parse code: False System.InvalidCastException: Specified cast is not valid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.