null异常在方法“MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)”中捕获,并且再也不会抛出

时间:2013-06-21 09:05:09

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


在下面的代码中,SelectedUser为null;我期望下面的代码抛出一个null异常,我可以在我的代码中处理某个例子:

Application.Current.DispatcherUnhandledException + = this.DispatcherUnhandledException; 要么 AppDomain.CurrentDomain.UnhandledException + = this.CurrentDomainUnhandledException;

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

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

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

二手技术
Windows 7 x64
.Net Framework 4.5
Visual Studio 2012 Update 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)'

由于

1 个答案:

答案 0 :(得分:1)

看起来WPF吞下了异常,这是由设计完成的。 更多相关信息: Why does WPF databinding swallow exceptions?