1

在我的应用程序中,我有以下用于保存 excel 文件的代码:

...
try {
  workbook.SaveAs(filename, ".xls");
}
catch (IOException ex) {
  MessageBox.Show(ex.Message, "Error saving file", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
...

如果“文件名”指定的文件正在使用中,则会发生 IOException,这是正常行为。但是,我们的一些客户发生了对 MessageBox.Show 的调用引发异常:


堆栈跟踪

System.ArgumentException: Object of type 'System.Collections.Generic.List`1[System.String]' cannot be converted to type 'System.String[]'.
----------------------------------------------------------------------
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast): 
----------------------------------------------------------------------
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr): 
----------------------------------------------------------------------
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig): 
----------------------------------------------------------------------
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks): 
----------------------------------------------------------------------
at System.Delegate.DynamicInvokeImpl(Object[] args): 
----------------------------------------------------------------------
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs): 
----------------------------------------------------------------------
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler): 
----------------------------------------------------------------------
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler): 
----------------------------------------------------------------------
at System.Windows.Threading.DispatcherOperation.InvokeImpl(): 
----------------------------------------------------------------------
at System.Threading.ExecutionContext.runTryCode(Object userData): 
----------------------------------------------------------------------
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData): 
----------------------------------------------------------------------
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx): 
----------------------------------------------------------------------
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state): 
----------------------------------------------------------------------
at System.Windows.Threading.DispatcherOperation.Invoke(): 
----------------------------------------------------------------------
at System.Windows.Threading.Dispatcher.ProcessQueue(): 
----------------------------------------------------------------------
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled): 
----------------------------------------------------------------------
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled): 
----------------------------------------------------------------------
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o): 
----------------------------------------------------------------------
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs): 
----------------------------------------------------------------------
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler): 
----------------------------------------------------------------------
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler): 
----------------------------------------------------------------------
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs): 
----------------------------------------------------------------------
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam): 
----------------------------------------------------------------------
at MS.Win32.UnsafeNativeMethods.MessageBox(HandleRef hWnd, String text, String caption, Int32 type): 
----------------------------------------------------------------------
at System.Windows.MessageBox.ShowCore(IntPtr owner, String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options): 
----------------------------------------------------------------------
at System.Windows.MessageBox.Show(String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon): 
----------------------------------------------------------------------

如果有人能对此提供任何见解,我将不胜感激。非常感谢您抽出宝贵时间。

4

0 回答 0