更新 ViewModel 中的属性后出现 NotImplementedException 0x80004001

发布于 2024-10-08 20:38:09 字数 3701 浏览 0 评论 0原文

上下文是 Windows Phone 7 的 Silverlight 应用程序。我正在使用模拟器进行调试。

我有一个 MainPage.xaml,其 DataContext 中附加了一个 ViewModel。
当页面NavigedTo时,会调用ViewModel中的方法来调用API并显示信息。

我有一个方法,它创建一个 Dictionary,用数据填充它并将其设置在实现 PropertyChanged 事件的属性中。

调用此方法后,调试器会在 App.Application_UnhandledException 中中断并出现 NotImplementedException。

如果我使用调试器跳过对此方法的调用,则不会引发异常。

奇怪的是,异常是在调用方法之后引发的,而不是在方法内部引发的!该异常不包含 InnerException。 HResult 为 -2147467263 以及一条包含“0x80004001”的消息。这是 StackTrace:

at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at Microsoft.Phone.Controls.Primitives.PanoramaPanel.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.Panorama.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.PhoneApplicationFrame.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

调试输出包含:

A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll (x10)
A first chance exception of type 'System.NotImplementedException' occurred in System.Windows.dll (x6)

The context is a Silverlight application for Windows Phone 7. I am debugging with the emulator.

I have a MainPage.xaml with a ViewModel attached in its DataContext.
When the page is NavigatedTo, a method is called in the ViewModel to call an API and display information.

I have a method which create a Dictionary<string, string>, fill it with data and set it in a property implementing the PropertyChanged event.

After this method is called, the debugger breaks in App.Application_UnhandledException with a NotImplementedException.

If I skip the call to this method with the debugger, the exception is not raised.

The strange thing is that the exception is raised after calling the method and not within! The exception contains no InnerException. There is a HResult of -2147467263 and a message containing "0x80004001". Here is the StackTrace:

at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at Microsoft.Phone.Controls.Primitives.PanoramaPanel.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.Panorama.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.PhoneApplicationFrame.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

The debugging output contains:

A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll (x10)
A first chance exception of type 'System.NotImplementedException' occurred in System.Windows.dll (x6)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的新欢旧爱 2024-10-15 20:38:09

哦哦。我通过检查 XAML 端的数据绑定发现了用户错误。这是我的 XAML:

<TextBlock Grid.Column="0" Text="{Binding Value}"
           Style="PhoneTextLargeStyle" />
<TextBlock Grid.Column="1" Text="{Binding Key}"
           Style="PhoneTextLargeStyle" />

我忘了写它是静态资源:

<TextBlock Grid.Column="0" Text="{Binding Value}"
           Style="{StaticResource PhoneTextLargeStyle}" />
<TextBlock Grid.Column="1" Text="{Binding Key}"
           Style="{StaticResource PhoneTextLargeStyle}" />

希望这个愚蠢的问题/自动回答能帮助某人:)

Ohw. I found a user error by checking databindings in the XAML side. Here is my XAML:

<TextBlock Grid.Column="0" Text="{Binding Value}"
           Style="PhoneTextLargeStyle" />
<TextBlock Grid.Column="1" Text="{Binding Key}"
           Style="PhoneTextLargeStyle" />

I forgot to write it's a static resource:

<TextBlock Grid.Column="0" Text="{Binding Value}"
           Style="{StaticResource PhoneTextLargeStyle}" />
<TextBlock Grid.Column="1" Text="{Binding Key}"
           Style="{StaticResource PhoneTextLargeStyle}" />

Let's hope this stupid question/auto-answer will help someone :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文