我还没有能够自己解决这个问题,所以我想我会给你一个机会。
程序本身正在将Outlook员工列表中的员工列表与PDL进行比较。问题是我的WPF表单在Windows 7上运行得非常好,但是当我尝试访问Outlook地址簿时,程序在Windows 10上崩溃,其他一切都按照它应该的方式运行。
这是访问Outlook的代码:
public class Outlookhelper
{
public List<String> GetDistributionListMembers()
{
List <String> returnlist = new List <String>();
Outlook.Application application = new Outlook.Application();
Outlook.SelectNamesDialog snd =
application.Session.GetSelectNamesDialog();
Outlook.AddressLists addrLists =
application.Session.AddressLists;
foreach (Outlook.AddressList addrList in addrLists)
{
if (addrList.Name == "Global Adress List")
{
snd.InitialAddressList = addrList;
break;
}
}
snd.NumberOfRecipientSelectors =
Outlook.OlRecipientSelectors.olShowTo;
snd.ToLabel = "D/L";
snd.ShowOnlyInitialAddressList = true;
snd.AllowMultipleSelection = false;
snd.Display();
if (snd.Recipients.Count > 0)
{
Outlook.AddressEntry addrEntry =
snd.Recipients[1].AddressEntry;
if (addrEntry.AddressEntryUserType ==
Outlook.OlAddressEntryUserType.
olExchangeDistributionListAddressEntry)
{
Outlook.ExchangeDistributionList exchDL =
addrEntry.GetExchangeDistributionList();
Outlook.AddressEntries addrEntries =
exchDL.GetExchangeDistributionListMembers();
if (addrEntries != null)
foreach (Outlook.AddressEntry exchDLMember
in addrEntries)
{
//System.Windows.Forms.MessageBox.Show(exchDLMember.Name);
returnlist.Add(exchDLMember.Name);
}
}
}
return returnlist;
}
}
这是我从Windows 10计算机上的事件查看器获得的错误消息:
Application: PDL Updater.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
at
System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(System.RuntimeType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(System.RuntimeType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(System.RuntimeType, System.Object[], Boolean)
at System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
at System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
at System.Activator.CreateInstance(System.Type, Boolean)
at System.Activator.CreateInstance(System.Type)
at PDLUpdater.Outlookhelper.GetDistributionListMembers()
at PDLUpdater.MainWindow.getPDLnames_Click(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)
at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
at System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent)
at System.Windows.UIElement.OnMouseUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
at System.Windows.Application.RunDispatcher(System.Object)
at System.Windows.Application.RunInternal(System.Windows.Window)
at Contacts.App.Main()
并且
Faulting application name: PDL Updater.exe, version: 1.2.9.0, time stamp: 0x58aae81e
Faulting module name: KERNELBASE.dll, version: 10.0.10586.589, time stamp: 0x57cf948c
Exception code: 0xe0434352
Fault offset: 0x0000000000071f28
Faulting process id: 0x2948
Faulting application start time: 0x01d28b7a4e508b20
Faulting application path: C:\Program Files\PDL Updater\PDL Updater.exe
Faulting module path: C:\WINDOWS\system32\KERNELBASE.dll
Report Id: dd5f897a-24c9-4dd0-979e-4f0cbd747a94
Faulting package full name:
Faulting package-relative application ID:
*编辑 这是它抛出我的消息,希望它有所帮助: Error Message
如果您还需要其他任何东西,我很乐意提供。期待结束这件事,所以提前谢谢你!
答案 0 :(得分:0)
尝试定位您的平台:
在Visual Studio中→项目属性→在构建选项卡→平台目标= X86 / X64 /任何CPU
更改平台目标并测试您的应用程序。
答案 1 :(得分:0)
您是否在辅助线程上运行代码?
请记住Office应用程序使用单线程单元模型。您应该仅在主线程上使用OOM。如果要使用多线程,则需要考虑使用低级API - 扩展MAPI。或者只是该API周围的任何包装器(例如,如Redemption)。
答案 2 :(得分:0)
当您尝试创建Outlook.Application对象的实例时,听起来确实会爆炸。
确保Outlook和您的应用都在相同的安全上下文中运行。应用程序是否以提升的权限运行(以管理员身份运行)?