EDIT
- This question is not: What is a NullReferenceException? A NullReferenceException occurs when a member is accessed of a reference which is null.
- This question is: How can a NullReferenceException occur when there is no member access?
END EDIT
As far as I know, a NullReferenceException
can only occur when a member of a reference type is being accessed. As far as I know, the "references" this
and base
can never be null.
Today I was confronted with a property which throws a NullReferenceException
, while there is NO member access (except for members of this
and base
).
My question is: How!
This is the code:
public class ComponentObject : Base
{
private readonly XmlNamespaceManager _nsmgr;
public XmlNode FieldGroupContainerWerknemers { get { ... } }
public string NumberOfMngDirectorMainShareholders
{
get
{
XmlNode fieldGroupContainerWerknemers = this.FieldGroupContainerWerknemers;
return base.GetValue(fieldGroupContainerWerknemers, this._nsmgr, "./ns1:FieldGroup//ns1:DynamicFields//ns1:Field[@Name='DgaAantal']//ns1:Value");
}
}
}
And this is the exception:
Exception type: NullReferenceException
Source: Turien.Interfaces.BizTalk.Policy.Helpers
Target Site: System.String get_NumberOfMngDirectorMainShareholders()
The following is a stack trace that identifies the location where the exception occured
at Turien.Interfaces.BizTalk.Policy.Helpers.BatchCertigo.ComponentObject.get_NumberOfMngDirectorMainShareholders()
at Turien.Interfaces.BizTalk.Policy.Helpers.BatchTurien.BatchE.BatchE.CreateCurrentCoverageData()
at Turien.Interfaces.BizTalk.Policy.Helpers.BatchTurien.BatchE.BatchE.CreateLetterDataBatchE()
at Turien.Interfaces.BizTalk.Policy.Helpers.BatchTurien.BatchE.BatchE.CreateContract()
at Turien.Interfaces.BizTalk.Policy.Helpers.BatchTurien.BatchE.BatchE.CreateBatch(XmlDocument outputdata)
at Turien.Interfaces.BizTalk.Policy.Helpers.BatchTurien.BatchBase`1.CreateBatch(XmlDocument outputdata, String fileName, Int32 outputNumber)
Steps I have taken:
- I searched for another property
NumberOfMngDirectorMainShareholders
: this is the only one. - I used ILSpy to spy inside the DLL. The code in production is the same as in source control.
EDIT
For the people who are telling be to debug: I'd love to. Come up with a suggestion where to put my breakpoint and which variables to check out. And further more: what to do with that information. For example: if this.FieldGroupContainerWerknemers
would be null, how would that cause this situation. Or if _nsmgr
is null, how would it cause this problem (keep in mind: the stacktrace points to THIS method / property!)