Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 12535 [details]
Sample code reproducing observed issue
Attempting to cast a value that has been boxed results in the following error message & crashes, even when the cast should be valid: "Cannot cast from source type to destination type"
For example, the following code fragment would produce this error:
int integer = 5;
object boxedValue = integer;
float castedToFloat = (float) boxedValue; //Cast error thrown
Please find attached example which demonstrates this behavior
This is painful inside of IValueConverter implementations where the values come in pre-boxed.
This is not actually an issue with Forms and is expected behavior within C# and the compiler. If you attempt to do the same thing within a basic console application you will run into the InvalidCastException. For more information on this you can read this post by Eric Lippert: