ja napisałem ten kod, aby zobaczyć nieprzeczytane elementy w moim perspektywicznej skrzynki pocztowej i oto kod:Nie można rzutować obiektu 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());
}
}
ale na pętli foreach jestem coraz to błąd:
"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))."
Czy możesz pomóc mi rozwiązać ten błąd?
jest ten dodatek? – Bolu
@Bolu Nie, to jest to, co piszę w mojej aplikacji C# Windows. – Zerotoinfinity
Mapifolder jest przestarzały, zamiast niego użyj Folder. –