[Mono-dev] InvalidCastException - which makes no sense

Edward Ned Harvey (mono) edward.harvey.mono at clevertrove.com
Fri Oct 24 21:48:30 UTC 2014


> From: Miguel de Icaza [mailto:miguel at xamarin.com]
> 
> What happens is this.   The value returned from ExecuteScalar is boxed.   This

Got it, thanks.  In fact, I simplified to this:

            Object foo = (Int64)0;
            Int64 foo64 = (Int64)foo;
            Int32 foo6432 = (Int32)(Int64)foo;
            Int32 foo32 = (Int32)foo;	// Throws InvalidCastException

And I confirmed the behavior is the same in .Net and Mono.  So everything makes sense; it's just something I didn't know before.


More information about the Mono-devel-list mailing list