Wpf 在方法”;MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)和#x201D;再也不扔了

Wpf 在方法”;MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)和#x201D;再也不扔了,wpf,c#-4.0,visual-studio-2012,entity-framework-5,sql-server-2012,Wpf,C# 4.0,Visual Studio 2012,Entity Framework 5,Sql Server 2012,在下面的代码中,SelectedUser为空;我希望下面的代码抛出一个null异常,我可以在代码的某个地方处理它,例如: Application.Current.DispatcherUnandledException+=此.DispatcherUnandledException; 或 AppDomain.CurrentDomain.UnhandledException+=此.CurrentDomainUnhandledException // Code example; here is the


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

Application.Current.DispatcherUnandledException+=此.DispatcherUnandledException; 或 AppDomain.CurrentDomain.UnhandledException+=此.CurrentDomainUnhandledException

// Code example; here is the SelectedUser null.
this.IsUserInRole = this.SelectedUser.UserRole;
不幸的是,在方法“MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)”中捕获了null异常,并且再也没有抛出它

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

使用的技术:
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设计完成的。 更多信息请点击此处:

感谢沃尔克提供了这一不错的解决方案。