双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

C#调用OutLook组件失败,急求高手诊断。

shineodin shineodin 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
一个小程序,C#读取本地联系人,在开发环境,和自己公司,一切正常,但是,在客户那边,不行了。可能是客户那边因为PC都在域控制中,所以又权限问题,请教各位有什么解决方法
主要代码如下
Microsoft.Office.Interop.Outlook.Application myOlApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace myNameSpace;
Microsoft.Office.Interop.Outlook.MAPIFolder myFloder;
myNameSpace = myOlApp.GetNamespace("MAPI").Session;
myFloder = myNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts;
StringBuilder xmlstr = new StringBuilder();
xmlstr.Append("<List>");
foreach (ContactItem foundContact in myFloder.Items)//遍历Outlook
{
if (foundContact.Email1Address.Contains(""))
{
xmlstr.Append("<Info>");
xmlstr.Append("<Account>");
xmlstr.Append(foundContact.Account);
xmlstr.Append("</Account>");
xmlstr.Append("<EntryID>");
xmlstr.Append(foundContact.EntryID);
xmlstr.Append("</EntryID>");
xmlstr.Append("<FirstName>");
xmlstr.Append(foundContact.FirstName);
xmlstr.Append("</FirstName>");
....
xmlstr.Append("</Info>");
}
}
xmlstr.Append("</List>");
....

出错信息
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063021-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).at OutlookTest.Program.Main(String[] args)

然后猜想说是权限问题,又以管理员权限运行
出错信息
System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).at OutlookTest.Program.Main(String[] args)
请高手帮个忙
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
shineodin
C# 111,129 成员 642,540 内容