Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 空引用异常取决于加载到哪个解决方案项目?_Visual Studio 2010_Nullreferenceexception - Fatal编程技术网

Visual studio 2010 空引用异常取决于加载到哪个解决方案项目?

Visual studio 2010 空引用异常取决于加载到哪个解决方案项目?,visual-studio-2010,nullreferenceexception,Visual Studio 2010,Nullreferenceexception,好吧,这个问题有点奇怪 我有一个在VS2010中构建的应用程序,它在自己的解决方案中运行良好。但是,如果我将项目加载到一个包含110多个项目的更大的解决方案中,我会开始出现NullReferenceExceptions,有时如果我继续跳过它们,它会正常工作,而其他时候则不会 然而,问题仍然存在:为什么当我将项目作为更大解决方案的一部分加载时,这些对象没有得到初始化,而不是在它自己的解决方案中加载时 编辑:以下是其中一个异常的堆栈跟踪示例: A first chance exception of

好吧,这个问题有点奇怪

我有一个在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)'

根据堆栈跟踪,ParentOrganDisplayName的getter具有NRE。所以你应该检查那里正在做什么


也许在您更大的解决方案中,您使用的应用程序略有不同?或者由于发生了更多的事情,一切都有点延迟,并且您的ViewModel或其他东西尚未正确初始化,即比赛状态。

嗯,我找到了为什么它在更大的解决方案中抛出异常,而不是在它自己的解决方案中抛出异常的原因:当异常发生时,它自己所在的解决方案没有中断!我打开了异常,果然在同一个地方抛出了相同的异常。

异常在哪里?堆栈跟踪是什么?是否有适当的方法来处理竞争条件?对于抛出异常的其中一个位置,getter只返回相应的属性。我只是添加了一个if条件,表示如果对象为null,则返回一个新对象。这似乎已经修复了那个实例,但这似乎不是一个好的解决方案。。。