简体   繁体   中英

Outlook COM Interop method event name conflict

I am using the Outlook com interface to automate the creation of emails. I am trying to handle the MailItem.Close Event but the problem is that MailItem also has a MailItem.Close() method. I was hoping the compiler would infer that i was referring to the event since I was trying to attach a delegate to it, however that is not the case.

private void editButton_Click(object sender, RoutedEventArgs e)
{
    outlook.MailItem editItem;
    ...
    editItem.Close += delegate { editItem_onClose(editItem); };
    ...
}

The actual error is:
Error 4 Cannot assign to 'Close' because it is a 'method group'

and the warning is:
Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Outlook._MailItem.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose)' and non-method 'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Close'. Using method group.

EDIT:

my Microsoft.Office.Interop.Outlook NameSpace does not have the ItemEvents_10_Event interface. I have outlook.ItemEvents_10_SinkHelper and outlook.ItemEvents_10 I tried to cast to outlook.ItemEvents_10 like so:

var events = (outlook.ItemEvents_10)editItem;
events.Close += delegate { editItem_AfterWrite(editItem, editRow); };

but I still get the "events.Close is a method group" error.

You need to cast the mail item object to the right interface or class which provides the event or method. The ItemEvents_10_Event interface provides the Close event and the MailItem class provides the Close method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM