c# - "COM target does not implement IDispatch" exception when opening Outlook.Contact -


my code straightforward:

using outlook = microsoft.office.interop.outlook;  private outlook.contactitem contact;  private void outlookbutton_click(object sender, routedeventargs e) {     try      {         contact = new outlook.contactitem((outlook.contactitem)((button)sender).tag);         contact.display(); 

the display() line raises exception related idispatch:

system.reflection.targetinvocationexception: com target not implement idispatch.

there outlook contact object bound buttons tag, , idea when button clicked open show them.

outlook (the application) not running. above works fine first time, if click on same button second time, exception above raised.

if tried using netoffice, gave me same result.

you can't create outlook items using class ctor. instead, need use createitem or createitemfromtemplate methods of application class.

also add method of items class can used create new outlook items.

most need correct code:

contact = (outlook.contactitem)((button)sender).tag); contact.display(); 

anyway, i'd recommend storing entry id value in tag instead. can use getitemfromid method of namespace class @ convinient time.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -