XamlParseException

时间:2019-03-13 06:48:54

标签: c# .net wpf sap

我尝试为wpf实现水晶报表。如果用户未安装所需的运行时,则应弹出一个消息框。

   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);
        }
    }

由于某种原因,我要打开的第一个MessageBox导致具有以下堆栈跟踪的InvalidCastException

  

bei SAPBusinessObjects.WPF.Viewer.PageNumberDisplayConverter.Convert(Object []值,类型targetType,Object参数,CultureInfo文化)      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(委托回调,对象args,Int32 numArgs)      bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象args,Int32 numArgs,委托catchHandler)      bei System.Windows.Threading.DispatcherOperation.InvokeImpl()      bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(对象状态)      bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executeContext,ContextCallback回调,对象状态,布尔类型saveSyncCtx)      bei System.Threading.ExecutionContext.Run(ExecutionContext executeContext,ContextCallback回调,对象状态,布尔类型saveSyncCtx)      bei System.Threading.ExecutionContext.Run(ExecutionContext executeContext,ContextCallback回调,对象状态)      bei MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executeContext,ContextCallback回调,对象状态)      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,布尔值和已处理)      bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,布尔值和已处理)      bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)      bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,Int32 numArgs)      bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象args,Int32 numArgs,委托catchHandler)      bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority优先级,TimeSpan超时,Delegate方法,对象args,Int32 numArgs)      bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam)      bei MS.Win32.UnsafeNativeMethods.MessageBox(HandleRef hWnd,字符串文本,字符串标题,Int32类型)      bei System.Windows.MessageBox.ShowCore(IntPtr所有者,字符串messageBoxText,字符串标题,MessageBoxButton按钮,MessageBoxImage图标,MessageBoxResult defaultResult,MessageBoxOptions选项)      bei System.Windows.MessageBox.Show(字符串messageBoxText,字符串标题,MessageBoxButton按钮,MessageBoxImage图标)      bei SapReportViewer.MainWindow.TryToInitializeReportViewer()在C:\ Users \ KlammerT \ Documents \ Visual Studio 2013 \ Projects \ SapReportViewer \ WpfApplication8 \ MainWindow.xaml.cs:Zeile 108中。      bei SapReportViewer.MainWindow..ctor()在C:\ Users \ KlammerT \ Documents \ Visual Studio 2013 \ Projects \ SapReportViewer \ WpfApplication8 \ MainWindow.xaml.cs:Zeile 73中。

如果我抓到InvalidCastException并尝试显示另一个MessageBox,它会很好地工作。

有人知道吗?

0 个答案:

没有答案