在下面的代码中 SelectedUser 为空;我希望下面的代码抛出一个空异常,我可以在代码中的某个地方处理它,例如:
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)'
谢谢