Hello,
In one of my activities I want to get my CustomApplication.
But if I trie the following i get an error(System.InvalidCastException: Cannot cast from source type to destination type.):
((CustomApplication)Application).DoSomething();
I'm using Monodroid 4.2.8.
I think this has worked in the past.
Is this a Bug or has something changed?
Thank you very much in advance for your answer.
Robin
Posts
I think you should say something more. I don't really know what you want to do? BUT:
Where does the Application-object come from? If you don't instantiate it by your self*) you can't cast it to your CustomApplication, because you can't cast a base-class to a derived-class! So it's definitely no bug.
*) means: CustomApplication c = new CustomApplication();
Yes, this is a bug: https://bugzilla.xamarin.com/show_bug.cgi?id=7934
The workaround is to set the
ApplicationAttribute.Name
property:Thank you it works.
Jonathan, how exactly is Name supposed to be? I've tried several variations but always get "application has stopped unexpectedly" followed by "assembly installation failed: The assembly directory could not be created."
Hi,
I rolled back to Mono For Android 4.2.5. Go to https://store.xamarin.com/, sign in, and download the Android from there. This error only happened with 4.2.8.
@MihaMarkic: My bad; it needs to be a Java name, not a JNI name:
I wish I could edit original answers after an hour...
That works :-)