在我的应用程序中,我有以下代码来保存excel文件:
...
try {
workbook.SaveAs(filename, ".xls");
}
catch (IOException ex) {
MessageBox.Show(ex.Message, "Error saving file", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
...
如果正在使用“filename”指定的文件,则会发生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):
----------------------------------------------------------------------
如果有人能对此提供任何见解,我将非常感激。非常感谢你的时间。