UPDATE: I fixed the problem I encountered, but I don't know why the error created a stack trace. The stack trace leads me in a completely wrong direction. If anyone can explain what is happening here, I would appreciate it (and mark your answer as accepted). Please note that my original message has been deleted.
I had the following class. Non-parts were deleted:
class ClassName { private string[] _accountTypes = new string[2] {"ECOM", "MOTO"}; private Dictionary<string, string> _settleDueDateDictionary = new Dictionary<string, string>() { {"0", "Process immediately."}, {"1", "Wait 1 day"}, {"2", "Wait 2 days"}, {"3", "Wait 3 days"}, {"4", "Wait 4 days"}, {"5", "Wait 5 days"}, {"6", "Wait 6 days"}, {"7", "Wait 7 days"}, }; private string _settleDueDate; private string _accountTypeDescription; public string SettleDueDate { get { DateTime today = DateTime.Today; long settleDueDate = Convert.ToInt64(_settleDueDate); return today.AddDays(settleDueDate).ToString("MM/dd/yyyy"); } set { if (!_settleDueDateDictionary.ContainsKey(value)) {
I also had this class that took an instance of the class above and created an XML string using the values ββfrom the instance:
class SecondClass { private ClassName classnameInstance; public SecondClass(ClassName instance) { classnameInstance = instance; } public string PrepareRequest(XMLWriter writer) { writer.WriteElementString("accounttypedescription", classnameInstance.AccountTypeDescription); } }
Here is the code for the client that generated the stack trace:
STPPData STPP = new STPPData(); STPP.SiteReference = _secureTradingWebServicesPaymentSettings.SiteReference; STPP.Alias = _secureTradingWebServicesPaymentSettings.Alias; STPP.SettleDueDate = Convert.ToString(_secureTradingWebServicesPaymentSettings.SettleDueDate); STPP.SettleStatus = _secureTradingWebServicesPaymentSettings.SettleStatus; STPPXml STPPXml = new STPPXml(STPP); XmlWriterSettings settings = new XmlWriterSettings(); settings.Async = false; var builder = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(builder, settings)) { string xmlRequest = STPPXml.PrepareRequest(writer); }
Finally, here is the stack trace:
mscorlib.dll!string.GetHashCode() mscorlib.dll!System.Collections.Generic.GenericEqualityComparer<System.__Canon>.GetHashCode(SYstem.__Canon obj) mscorlib.dll!System.Collections.Generic.Dictionary<string,string>.FindEntry(string key) mscorlib.dll!System.Collections.Generic.Dictionary<System.__Canon,System.__Canon>.ContainsKey(System.__Canon key) ClassName.SettleDueDate.set(string value) ClassName.SettleDueDate.set(string value) ClassName.SettleDueDate.set(string value)
This stack trace makes me think that I did not properly implement the receiver / setter for STPP.SettleDueDate. I checked them, and the backup variable, etc. It was correct (the usual reasons for loops in getters / setters, I understand). Further debugging showed me that the stack trace was actually generated when this PrepareRequest() line was PrepareRequest() :
writer.WriteElementString("accounttypedescription", STPPData.AccountTypeDescription);
I found that I used getter incorrectly for STPPData.AccountTypeDescription because I created the backing property that I used in setter, but I did NOT use the backing property in getter:
public string AccountTypeDescription { get {
My question is:
Why does the stack trace of a StackOverflowException object point me to SettleDueDate.set () when the error was actually inside AccountTypeDescription.get ()?
Note. I am new to C # and am coming from the LAMP background. I simplified the code a bit, but I donβt think I deleted anything important.