Ho scritto questo codice per visualizzare gli elementi non letti nella mia casella di posta di Outlook e qui è il codice:Impossibile eseguire il cast oggetto COM - Outlook Microsoft & C#
Microsoft.Office.Interop.Outlook.Application app;
Microsoft.Office.Interop.Outlook.Items items;
Microsoft.Office.Interop.Outlook.NameSpace ns;
Microsoft.Office.Interop.Outlook.MAPIFolder inbox;
Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
app = application;
ns = application.Session;
inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
items = inbox.Items;
foreach (Microsoft.Office.Interop.Outlook.MailItem mail in items)
{
if (mail.UnRead == true)
{
MessageBox.Show(mail.Subject.ToString());
}
}
ma sul ciclo foreach sto ottenendo questo errore:
"Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
Potete aiutarmi come risolvere questo errore?
è presente un componente aggiuntivo? – Bolu
@Bolu No, questo è ciò che sto scrivendo nella mia applicazione Windows C# – Zerotoinfinity
MAPIFolder è obsoleto, utilizzare invece Cartella. –