Sunday, October 28, 2018

c# - InvalidCastException on MessageBox after XamlParseException

I try to implement crystal reports for wpf. If the user does not have the required runtime installed, a messagebox should pop up.



   private void TryToInitializeReportViewer()
{
try
{
reportViewer = new CrystalReportsViewer
{
ShowExportButton = false,
ShowOpenFileButton = false,
ShowRefreshButton = false,
ShowCopyButton = false,
ShowStatusbar = true,
ShowLogo = false,
Visibility = Visibility.Collapsed
};

ViewerGrid.Children.Add(reportViewer);
}
catch (XamlParseException ex)
{
Log.GetInstance().Error(LogUtil.Customize("ReportViewer konnte nicht initislisiert werden"), ex);

MessageBox.Show(
"Das Ausgabeformat 'REPORT' ist nicht verfügbar, da die CrystalReports Runtime nicht installiert ist", "Achtung", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}


For some reason the first MessageBox I want to open leads to a InvalidCastException with the following stacktrace:




bei SAPBusinessObjects.WPF.Viewer.PageNumberDisplayConverter.Convert(Object[] value, Type targetType, Object parameter, CultureInfo culture)
bei System.Windows.Data.MultiBindingExpression.TransferValue()
bei System.Windows.Data.MultiBindingExpression.Transfer()
bei System.Windows.Data.MultiBindingExpression.UpdateTarget(Boolean includeInnerBindings)
bei System.Windows.Data.MultiBindingExpression.AttachToContext(Boolean lastChance)
bei System.Windows.Data.MultiBindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
bei MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
bei MS.Internal.Data.DataBindEngine.Run(Object arg)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
bei System.Windows.Threading.DispatcherOperation.InvokeImpl()
bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Windows.Threading.DispatcherOperation.Invoke()
bei System.Windows.Threading.Dispatcher.ProcessQueue()
bei System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
bei MS.Win32.UnsafeNativeMethods.MessageBox(HandleRef hWnd, String text, String caption, Int32 type)
bei System.Windows.MessageBox.ShowCore(IntPtr owner, String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options)
bei System.Windows.MessageBox.Show(String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon)
bei SapReportViewer.MainWindow.TryToInitializeReportViewer() in C:\Users\KlammerT\Documents\Visual Studio 2013\Projects\SapReportViewer\WpfApplication8\MainWindow.xaml.cs:Zeile 108.
bei SapReportViewer.MainWindow..ctor() in C:\Users\KlammerT\Documents\Visual Studio 2013\Projects\SapReportViewer\WpfApplication8\MainWindow.xaml.cs:Zeile 73.




If I catch the InvalidCastException and try to show another MessageBox it works perfectly.



Anybody an idea?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...