【问题标题】:First chance exception of type System.NullReference exception in PresentationFramework.dll?PresentationFramework.dll 中 System.NullReference 类型异常的第一次机会异常?
【发布时间】:2012-02-10 16:37:46
【问题描述】:

我无法找出我的应用程序中发生的异常。

基本上,我正在托管一个 wpf 用户控件,其中包含一个基础架构 XamDataGrid。

当我关闭应用程序时,我得到一个类型异常的无限循环:

线程 '' (0x24020) 已退出,代码为 0 (0x0)。 PresentationFramework.dll 中出现“System.NullReferenceException”类型的第一次机会异常 PresentationFramework.dll 中出现“System.NullReferenceException”类型的第一次机会异常 PresentationFramework.dll 中出现“System.NullReferenceException”类型的第一次机会异常
等等……

如果我删除 XAMDATAGRID,一切正常...所以我猜这是网格的问题...

堆栈跟踪的一部分是:(我不确定这是否有帮助:)

----------------------------------------------- -------------------------------------------- PresentationFramework.dll!系统。 Windows.DeferredAppResourceReference.GetValue(System.Windows.BaseValueSourceInternal valueSource = Inherited) + 0x4d 字节

WindowsBase.dll!System.Windows.DependencyObject.GetEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.RequestFlags请求)+ 0xe6 字节

WindowsBase.dll!System.Windows.DependencyObject.GetValueEntry(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.PropertyMetadata 元数据 = {System.Windows.FrameworkPropertyMetadata }, System.Windows.RequestFlags requests = FullyResolved) + 0x2fe 字节

WindowsBase.dll!System.Windows.DependencyObject.GetValue(System.Windows.DependencyProperty dp) + 0x48 字节 PresentationFramework.dll!MS.Internal.Text.TextProperties.InitCommon(System.Windows.DependencyObject 目标 = {System.Windows.Controls.TextBlock}) + 0x6b 字节 PresentationFramework.dll!MS.Internal.Text.TextProperties.TextProperties(System.Windows.FrameworkElement target = {System.Windows.Controls.TextBlock}, bool isTypographyDefaultValue = true) + 0x42 字节
PresentationFramework.dll!System.Windows.Controls.TextBlock.GetLineProperties() + 0x37 字节
PresentationFramework.dll!System.Windows.Controls.TextBlock.EnsureTextBlockCache() + 0x2f 字节 PresentationFramework.dll!System.Windows.Controls.TextBlock.MeasureOverride(System.Windows.Size 约束) + 0x50 字节
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1ee 字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x249 字节
PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement 元素,System.Windows.Size 约束)+ 0xfe 字节
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size 约束) + 0x18 字节 PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1ee 字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x249 字节
PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size 约束) + 0x10c 字节 PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1ee 字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x249 字节
PresentationFramework.dll!System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size 约束)+ 0x187 字节
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1ee 字节
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x249 字节
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size 约束) + 0x1cf 字节


非常感谢任何有关如何解决此问题的帮助!谢谢!

【问题讨论】:

  • 如何将代码放在实例化您正在使用的 Grid 的位置.. 您是否还在项目级别添加了引用.. 除了使用...??
  • 嗨,我是 wpf 的新手,所以如果我不清楚,我很抱歉......它只是一个简单的 XamDataGrid......我将它实例化为 Xamdatagrid grid = new Xamdatagrid(); grid.Datasource = mysource;然后我将它作为 sp.Children.Add(grid) 添加到 StackPanel。这能回答你的问题吗?谢谢!
  • 我们可以看看一些代码吗..它可能会有所帮助
  • 好的...我会尝试把一些东西放在一起。
  • 酷.. 我相信 StackOverFlow 上的其他帮助者想看看你在做什么..特别是在初始化部分谢谢

标签: c# wpf infragistics


【解决方案1】:

发生该错误是因为当 winforms 应用程序关闭时,WPF 调度程序线程尚未完成刷新它的挂起队列以获取事件消息。当它开始这样做时,应用程序对象已经关闭并被清空。要解决此问题,在宿主窗口关闭之前,只需在 WPF 消息循环上调用 shutdown。

Application.Current.Dispatcher.InvokeShutdown()

【讨论】:

  • 谢谢@outro56。这真的节省了我的时间。太棒了:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-22
  • 2013-06-21
  • 1970-01-01
  • 2014-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多