Hi,
Have an app which has been running fine for a while. All of a sudden it has started throwing intermitent "Object reference not set...." errors at a certain line of code on the product server.
I started the app in Visual Studio and debugged it with a breakpoint at the offending line of code and have replicated a really strange behaviour.
Initially when VS breaks at the line of code breakpoint, the variable is NULL but if I wait 5 secs or so then the variable is no longer NULL. This can be sped up by calling the variable in the Immediate Window in VS which causes the NULL field to populate or resolve instantly. This is the exact intermitent nature of the error on the production server.
Any ideas where to start? The data is loaded into the variable before hitting the method but for some reason there is a lag in referencing the variable in memory. Heaps of available memory on dev and production servers.
Really strange...need help to locate a place to start to resolve it.
Thanks in advance.
Info : .NET 3.5, VS 2008
Code :
public static List<Model> CreateModel(List<subModelA> subModelAs, List<subModelB> subModelBs, int duration, bool isGroup) {
List<Model> result = new List<Model>();
try {
if (subModelAs != null && subModelAs.Count > 0) {
if (subModelBs != null && subModelBs.Count > 0) {
subModelBs.ForEach(b => {
subModelA a = subModelAs.Find(x => x.id == b.comp[0].subModelAComp.subModel.id);
result.Add(CreateNewModel(a, b, duration));
});
}
}
}
catch (Exception ex) {
throw ex;
}
return result;
}
The following line is the source of the issue :
subModelA a = subModelAs.Find(x => x.id == b.comp[0].subModelAComp.subModel.id);
If Sometimes b is NULL and other times subModelAComp is NULL. If i breakpoint this line and in the Immediate Window if i execute "b.comp[0].subModelAComp" it is NULL, i then execute "b" and then execute "b.comp[0].subModelAComp" again and it is no longer NULL. The call to "b" seems to force the "subModelAComp" to not be NULL. There is no code in the getters which could cause this change.
* The application is not threaded. No multi-threading implemented **