locked
C# Error "Unable to cast object of type 'System.Windows.Controls.TextBox' to type 'System.IConvertible'." RRS feed

  • Question

  • Hello,

    My C# App For Windows Phone 8.1 crashes with the Error 

    "An exception of type 'System.InvalidCastException' occurred in mscorlib.ni.dll but was not handled in user code

    Additional information: Unable to cast object of type 'System.Windows.Controls.TextBox' to type 'System.IConvertible'."

    At 

                int Ausgerechnetes = (Convert.ToInt32(Ergebniss));
                if (Ausgerechnetes == (Convert.ToDecimal(AufgabeZahl1)) + (Convert.ToDecimal(AufgabeZahl2)))
                { MessageBox.Show("Richtig!"); }

    Do You know where the Problem is?

    Thank You,

    Friedrich


    • Moved by Youjun Tang Wednesday, January 28, 2015 5:25 AM more related to suggestion forum
    Tuesday, January 27, 2015 8:28 PM

Answers

  • Hi FriedrichT,

    Per my understanding, you should forget to add Text property to that three TextBox property. Try to modify the code as the following. Try it and let me know the result.

    int Ausgerechnetes = (Convert.ToInt32(Ergebniss.Text));
    
                if (Ausgerechnetes == (Convert.ToDecimal(AufgabeZahl1.Text)) + (Convert.ToDecimal(AufgabeZahl2.Text)))
    
                { MessageBox.Show("Richtig!"); }
    

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, January 28, 2015 7:08 AM

All replies

  • Hi FriedrichT,

    Per my understanding, you should forget to add Text property to that three TextBox property. Try to modify the code as the following. Try it and let me know the result.

    int Ausgerechnetes = (Convert.ToInt32(Ergebniss.Text));
    
                if (Ausgerechnetes == (Convert.ToDecimal(AufgabeZahl1.Text)) + (Convert.ToDecimal(AufgabeZahl2.Text)))
    
                { MessageBox.Show("Richtig!"); }
    

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, January 28, 2015 7:08 AM
  • Hi Herro Wong,

    It worked - there isn't anymore the error and it Works.

    Thank you for your help.


    Wednesday, January 28, 2015 10:24 AM