【问题标题】:The null exception is caught in the method” MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)” and never thrown again空异常被方法“MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)”捕获,不再抛出
【发布时间】:2013-06-21 09:05:08
【问题描述】:


在下面的代码中 SelectedUser 为空;我希望下面的代码抛出一个空异常,我可以在代码中的某个地方处理它,例如:

Application.Current.DispatcherUnhandledException += this.DispatcherUnhandledException; 或者 AppDomain.CurrentDomain.UnhandledException += this.CurrentDomainUnhandledException;

// Code example; here is the SelectedUser null.
this.IsUserInRole = this.SelectedUser.UserRole;

不幸的是,在方法“MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)”中捕获了null异常,并且再也没有抛出它。

我认为这是 .Net 库中的一个错误;我在网上找不到有关该问题的任何有用信息。任何帮助将不胜感激!

使用的技术:
Windows 7 x64
.Net Framework 4.5
Visual Studio 2012 更新 2

底层:
WPF
实体框架
SQL Server 2012

调用堆栈:

Cannot get 'IsUserInRole' value (type 'Boolean') from '' (type 'DataGridViewModel'). BindingExpression:Path=IsUserInRole; DataItem='DataGridViewModel' (HashCode=22143992); target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
...UserInterface.Settings.DataGridViewModel.get_IsUserInRole() in …….\SettingsModule\UserSettingsView\DataGridViewModel.cs:line 521
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level)
at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)'

谢谢

【问题讨论】:

    标签: wpf c#-4.0 visual-studio-2012 entity-framework-5 sql-server-2012


    【解决方案1】:

    看起来异常被 WPF 所吞并,这是由设计完成的。 更多关于这里: Why does WPF databinding swallow exceptions?

    【讨论】:

    • 感谢 Volker 提供了这个不错的解决方案。
    猜你喜欢
    • 2010-09-13
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-08-30
    • 2010-10-14
    • 2021-01-15
    • 2013-06-24
    • 2021-09-02
    相关资源
    最近更新 更多