0

Okay, this problem is a bit odd.

I have an application built in VS2010 that runs fine in it's own solution. However, if I load the project into a bigger solution (with 110+ projects), I start getting NullReferenceExceptions, and sometimes if I continue past them it works fine, and other times it doesn't.

The question remains, though: Why are these objects not getting initialized when I load the project as part of a bigger solution, but not when it's in it's own solution?

EDIT: Here's a sample stack trace for one of the exceptions:

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)'
Saggio
  • 2,212
  • 6
  • 33
  • 50

2 Answers2

0

According to the stack trace, the getter of ParentOrganDisplayName has a NRE. So you should check what is being done there.

Perhaps in your bigger solution you are using the app slightly differently? Or (due to more stuff going on) everything is a bit delayed and your ViewModel (or something else) hasn't yet initialized properly (a.k.a. race condition).

Daniel Rose
  • 17,233
  • 9
  • 65
  • 88
  • Is there a proper way to deal with race conditions? For one of the places the exception was being thrown the getter just returns the respective property. I simply added an if condition saying that if the object is null, return a new object. This seems to have fixed that instance, but that doesn't seem like a good solution... – Saggio Apr 28 '11 at 15:35
0

Well, I found the reason why it's throwing the exception in the bigger solution and not in the solution where it's by itself: The solution where it is by itself wasn't breaking when exceptions occur! I turned exceptions on and sure enough, the same exceptions in the same place were being thrown.

Saggio
  • 2,212
  • 6
  • 33
  • 50