C#调用OutLook组件失败,急求高手诊断。
一个小程序,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 inte易做图ce type 'Microsoft.Office.Interop.Outlook.ContactItem'. This operation failed because the QueryInte易做图ce call on the COM component for the inte易做图ce with IID '{00063021-0000-0000-C000-000000000046}' failed due to the following error: No such inte易做图ce 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)
请高手帮个忙
补充:.NET技术 , C#