_sponsorOrBankFacingBorrowerCompanyWizardData = CompanyData.GetCompanyWizardData(SponsorOrBankFacingBorrowerCompany.CompanyID);
So the problem here is that the code tries to go into this statement no matter what, I want it to only go if it CAN go, obviously.
However, if I perform a watch in Visual Studio 2010 ONLY on this object SponsorOrBankFacingBorrowerCompany
, no properties, methods, anything, I get a null reference exception.
How do I check for null when I get an exception before the check even happens?
Here's the watch:
EDIT:
public STPProject STPData
{
get { return _STPData; }
set
{
_STPData = value;
//set WebIds
foreach (STPCompany comp in _STPData.STPCompanyCollection)
{
comp.WebId = comp.WebId < 1 ? GetNextWebId() : comp.WebId;
foreach (STPContact cont in comp.STPContactCollection)
{
cont.WebId = cont.WebId < 1 ? GetNextWebId() : cont.WebId;
}
}
//must be before AttachSTPEvents
_STPData.AffiliateTradeIndicator = _STPData.AffiliateTradeIndicator.HasValue ? _STPData.AffiliateTradeIndicator.Value : false;
//set company wizard defaults
_sponsorOrBankFacingBorrowerCompanyWizardData = CompanyData.GetCompanyWizardData(SponsorOrBankFacingBorrowerCompany.CompanyID);
AttachSTPEvents(_STPData);
}
}
Getter for other that is throwing exception:
public STPCompany SponsorOrBankFacingBorrowerCompany
{
get
{
if (STPData.AffiliateTradeIndicator.Value)
{
return BankFacingBorrower;
}
else
{
return Sponsor;
}
}
}