好的,這個問題有點奇怪。取決於解決方案項目加載到哪個空引用異常?
我有一個內置於VS2010的應用程序,可以在自己的解決方案中正常運行。但是,如果我將項目加載到更大的解決方案(包含110個以上的項目)中,我開始得到NullReferenceExceptions,並且有時如果我繼續過去,它可以正常工作,而其他時間則不會。
但問題依然存在:爲什麼當我作爲更大的解決方案的一部分加載項目時,這些對象沒有被初始化,但是當它在它自己的解決方案中時,卻沒有被初始化?
編輯:下面是一個例外的樣本堆棧跟蹤:
A first chance exception of type 'System.NullReferenceException' occurred in DemoApp.exe
Additional information: Object reference not set to an instance of an object.
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
System.Windows.Data Error: 17 : Cannot get 'ParentOrganDisplayName' value (type 'String') from '' (type 'OrganLocationViewModel'). BindingExpression:Path=ParentOrganDisplayName; DataItem='OrganLocationViewModel' (HashCode=19153159); target element is 'TextBox' (Name='organParentNameTxt'); target property is 'Text' (type 'String') 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.
at DemoApp.ViewModel.OrganLocationViewModel.get_ParentOrganDisplayName() in C:\Visual Studio 2010\Projects\DemoApp\ViewModel\OrganLocationViewModel.cs:line 100
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
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)'
哪裏例外?什麼是堆棧跟蹤? – SLaks 2011-04-28 14:25:43