Error converting Java.Lang.Onject to System.Object

Hi,

I'm making an example to read mails from gmail or any IMAP mail account using JavaMail Android, but I have a problem converting java.lang.Object to MimeMultipart.

The problem is that the MimeMultipart class inherits from System.Object.
I put a link to the example.
https://www.dropbox.com/s/edq3bw1ex40fq3l/LeerCorreos.zip

Thank you very much.

Posts

  • JonathanPryorJonathanPryor Xamurai USXamarin Team Xamurai

    One thing that confuses me is Activity1.cs:112:

    MimeMultipart multi = messages[i].Content.Cast<MimeMultipart>();
    
    if (messages[i].Content is Multipart)
    

    Given that your .Cast<T>() extension method something, it's puzzling that you use .Cast<T>() then ignore the return value; should't it instead be?

    MimeMultipart multi = messages[i].Content.Cast<MimeMultipart>();
    
    if (multi is Multipart)
    

    Furthermore, I would suggest that you try to use the .JavaCast<T>() extension method, as you may be hitting Bug 7459. The workaround is to use:

    var multi = messages[i].Content.Cast<MimeMultipart>() ??
        messages[i].Content.JavaCast<MimeMultipart>();
    
Sign In or Register to comment.