我试图在Visual Studio中加载XAML文件,但它抛出了一个异常,但当我运行应用程序时,设计和所有功能都非常好。异常如下:
InvalidCastException: Unable to cast object of type 'System.Windows.Application' to type 'Omnia.PIE.VTA.App'.
at Omnia.PIE.VTA.MainWindow.get_Instance()
at Omnia.PIE.VTA.Views.AccountHolderInfo.UserControl_Loaded(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
提前说声抱歉,我是Visual Studio的初学者,在花费几个小时后,仍然无法解决它。
Omnia.PIE.VTA.Views.AccountHolderInfo
的控件,Visual Studio XAML 设计器试图初始化它,但在UserControl_Loaded
中抛出异常。如果您拥有AccountHolderInfo
的源代码,则可以对其进行调试。打开第二个 Visual Studio,转到“调试”菜单,然后选择“附加到进程”,搜索 devenv.exe 并选择它。然后打开“调试”>“窗口”>“异常设置”,并标记“常见语言运行时异常”。然后再次尝试打开 XAML 编辑器,第二个 Visual Studio 实例会中断并显示异常发生的位置。 - Misaz