Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XamlParseException后MessageBox上的InvalidCastException_C#_.net_Wpf_Sap - Fatal编程技术网

C# XamlParseException后MessageBox上的InvalidCastException

C# XamlParseException后MessageBox上的InvalidCastException,c#,.net,wpf,sap,C#,.net,Wpf,Sap,我尝试为wpf实现crystal报表。如果用户没有安装所需的运行时,则应弹出一个messagebox private void TryToInitializeReportViewer() { try { reportViewer = new CrystalReportsViewer { ShowExportButton = false, S

我尝试为wpf实现crystal报表。如果用户没有安装所需的运行时,则应弹出一个messagebox

   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);
        }
    }
出于某种原因,我要打开的第一个
消息框
导致了一个
无效的castexception
,具有以下堆栈跟踪:

bei SAPBusinessObjects.WPF.Viewer.PageNumberDisplayConverter.Convert(对象[]值,类型targetType,对象参数,文化信息文化) bei System.Windows.Data.MultiBindingExpression.TransferValue() bei System.Windows.Data.MultiBindingExpression.Transfer() bei System.Windows.Data.MultiBindingExpression.UpdateTarget(布尔includeInnerBindings) bei System.Windows.Data.MultiBindingExpression.AttachToContext(布尔lastChance) bei System.Windows.Data.MultiBindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(布尔lastChance) bei MS.Internal.Data.DataBindEngine.Task.Run(布尔lastChance) bei MS.Internal.Data.DataBindEngine.Run(对象参数) bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调、对象参数、Int32 numArgs) bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源、委托回调、对象参数、Int32 numArgs、委托catchHandler) bei System.Windows.Threading.DispatcherOperation.InvokeImpl() bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(对象状态) bei System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保留SyncCTX) bei System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保留SyncCTX) bei System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态) bei MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext,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、Boolean和handled) bei MS.Win32.HwndWrapper.WndProc(IntPtr-hwnd、Int32-msg、IntPtr-wParam、IntPtr-lParam、Boolean和handled) bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(对象o) bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调、对象参数、Int32 numArgs) bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源、委托回调、对象参数、Int32 numArgs、委托catchHandler) bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority优先级、TimeSpan超时、委托方法、对象参数、Int32 numArgs) bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam) bei MS.Win32.unsafentiveMethods.MessageBox(HandleRef hWnd、字符串文本、字符串标题、Int32类型) bei System.Windows.MessageBox.ShowCore(IntPtr所有者、字符串messageBoxText、字符串标题、MessageBoxButton按钮、MessageBoxImage图标、MessageBoxResult默认结果、MessageBoxOptions选项) bei System.Windows.MessageBox.Show(字符串messageBoxText、字符串标题、MessageBoxButton按钮、MessageBoxImage图标) 在C:\Users\KlammerT\Documents\Visual Studio 2013\Projects\SapReportViewer\WPFAapplication8\MainWindow.xaml.cs:Zeile 108中输入bei SapReportViewer.MainWindow.trytInitializeReportViewer()。 C:\Users\KlammerT\Documents\Visual Studio 2013\Projects\SapReportViewer\WPFAApplication8\MainWindow.xaml.cs:Zeile 73中的bei SapReportViewer.MainWindow..ctor()

如果我捕捉到
InvalidCastException
并尝试显示另一个
消息框
,它将非常有效


有人知道吗?

我认为例外情况与报表的某些无效状态有关,我猜消息框只是在报表查看器中触发了一些代码,但它不在有效状态。查看是否存在与此相同的问题,使报表无效:我现在不加载报表,因此我不认为它与无效报表有关。我认为异常与报表的某些无效状态有关,我猜消息框只是在报表查看器中的某些代码处于无效状态时触发。看看你是否有与此相同的问题使报告无效:我现在不加载报告,因此我认为它与无效报告无关