c# - Getting a random stack overflow when calling .SubmitChanges() linq -


i stackoverflow exception when calling {datacontext}.submitchanges()... wish knew lines of code post clarify situation exception not give information when thrown says:

an unhandled exception of type 'system.stackoverflowexception' occurred in mscorlib.dll 

and in view detail get:

{cannot evaluate expression because current thread in stack overflow state.} 

i have looked through of properties in view model make sure declared correctly , there no issues causing stackoverflow exception there...it occurs after when submitchanges() called.

here code submit gets called:

public void verifyadvancepaymentsandsave()         {             try             {                 if (!verifytakehomeactualbreakdownforadvancepayments())                 {                     messagebox.show(                         "cash, check, , money order fields must add amount in take home actual field!",                         "validation error!", messageboxbutton.ok, messageboximage.exclamation);                      return;                 }                  if (messagebox.show("are sure want save payment?", "save", messageboxbutton.yesno, messageboximage.question) != messageboxresult.yes)                     return;                  if (!usercontroller.createusercontroller().checkaccess(usercontroller.restrictedaccessaction.editcollections))                 {                     return;                 }                  if (initialcollectionaction == collectionaction.viewadvancepayment)                 {                     foreach (advance in advances)                     {                         foreach (advancepayment ap in a.advancepayments)                         {                             advancepayment newap = sp.advancepayments.where(adv => adv.id == ap.id).singleordefault();                              if (newap != null)                             {                                 newap.payment = ap.payment;                                 newap.issaved = false;                             }                             else                             {                                 messagebox.show("could not find advance payment apply amount to!");                                 return;                             }                         }                     }                 }                 else                 {                     try                     {                         currentcollection.status = batchstatus.open.tostring();                         currentcollection.collectiondate = datetime.now;                         currentcollection.isadvancedpayment = true;                         currentcollection.collectionmachines = null;                           //sp.collections.insertonsubmit(currentcollection);                     }                     catch                     {                         messagebox.show("error inserting changes!");                     }                 }                  try                 {                     sp.submitchanges();                      if (initialcollectionaction == collectionaction.viewadvancepayment)                         messagebox.show("advance payment saved successfully!");                     else                         messagebox.show("advance payment submitted sucessfully!");                      closetab();                 }                 catch                 {                     messagebox.show("error submitting changes!");                 }             }             catch (exception ex)             {                 string message = usercontroller.createusercontroller().loggedinuser.username + "\n" + ex.message + "\n" + ex.stacktrace;                 emailcontroller.createemailcontroller().sendemail("urm error", message);             }         } 

stack trace - before submitchanges() call

   @ urm.viewmodels.collectionsviewmodel.verifyadvancepaymentsandsave()    @ urm.commands.collectionssavecommand.execute(object parameter)    @ ms.internal.commands.commandhelpers.criticalexecutecommandsource(icommandsource commandsource, boolean userinitiated)    @ system.windows.controls.primitives.buttonbase.onclick()    @ system.windows.controls.button.onclick()    @ system.windows.controls.primitives.buttonbase.onmouseleftbuttonup(mousebuttoneventargs e)    @ system.windows.uielement.onmouseleftbuttonupthunk(object sender, mousebuttoneventargs e)    @ system.windows.input.mousebuttoneventargs.invokeeventhandler(delegate generichandler, object generictarget)    @ system.windows.routedeventargs.invokehandler(delegate handler, object target)    @ system.windows.routedeventhandlerinfo.invokehandler(object target, routedeventargs routedeventargs)    @ system.windows.eventroute.invokehandlersimpl(object source, routedeventargs args, boolean reraised)    @ system.windows.uielement.reraiseeventas(dependencyobject sender, routedeventargs args, routedevent newevent)    @ system.windows.uielement.onmouseupthunk(object sender, mousebuttoneventargs e)    @ system.windows.input.mousebuttoneventargs.invokeeventhandler(delegate generichandler, object generictarget)    @ system.windows.routedeventargs.invokehandler(delegate handler, object target)    @ system.windows.routedeventhandlerinfo.invokehandler(object target, routedeventargs routedeventargs)    @ system.windows.eventroute.invokehandlersimpl(object source, routedeventargs args, boolean reraised)    @ system.windows.uielement.raiseeventimpl(dependencyobject sender, routedeventargs args)    @ system.windows.uielement.raisetrustedevent(routedeventargs args)    @ system.windows.uielement.raiseevent(routedeventargs args, boolean trusted)    @ system.windows.input.inputmanager.processstagingarea()    @ system.windows.input.inputmanager.processinput(inputeventargs input)    @ system.windows.input.inputprovidersite.reportinput(inputreport inputreport)    @ system.windows.interop.hwndmouseinputprovider.reportinput(intptr hwnd, inputmode mode, int32 timestamp, rawmouseactions actions, int32 x, int32 y, int32 wheel)    @ system.windows.interop.hwndmouseinputprovider.filtermessage(intptr hwnd, windowmessage msg, intptr wparam, intptr lparam, boolean& handled)    @ system.windows.interop.hwndsource.inputfiltermessage(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled)    @ ms.win32.hwndwrapper.wndproc(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled)    @ ms.win32.hwndsubclass.dispatchercallbackoperation(object o)    @ system.windows.threading.exceptionwrapper.internalrealcall(delegate callback, object args, int32 numargs)    @ ms.internal.threading.exceptionfilterhelper.trycatchwhen(object source, delegate method, object args, int32 numargs, delegate catchhandler)    @ system.windows.threading.dispatcher.legacyinvokeimpl(dispatcherpriority priority, timespan timeout, delegate method, object args, int32 numargs)    @ ms.win32.hwndsubclass.subclasswndproc(intptr hwnd, int32 msg, intptr wparam, intptr lparam)    @ ms.win32.unsafenativemethods.dispatchmessage(msg& msg)    @ system.windows.threading.dispatcher.pushframeimpl(dispatcherframe frame)    @ system.windows.threading.dispatcher.pushframe(dispatcherframe frame)    @ system.windows.threading.dispatcher.run()    @ system.windows.application.rundispatcher(object ignore)    @ system.windows.application.runinternal(window window)    @ system.windows.application.run(window window)    @ system.windows.application.run()    @ urm.app.main()    @ system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args)    @ system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args)    @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly()    @ system.threading.threadhelper.threadstart_context(object state)    @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)    @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)    @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state)    @ system.threading.threadhelper.threadstart() 

models used in view model:

public class advancepaymentsmodel : inotifypropertychanged     {         public int advanceid { get; set; }         public string paymentid { get; set; }         public decimal payment { get; set; }         public datetime paymentdate { get; set; }          private string _status;         public string status         {                         {                 return _status;             }              set             {                 _status = value;                 onpropertychanged("status");             }         }          private brush _brushobj;         public brush brushobj         {                         {                 return _brushobj;             }              set             {                 _brushobj = value;                 onpropertychanged("brushobj");             }         }          private advancepayment _advancepayment;         public advancepayment advancepayment         {                         {                 return _advancepayment;             }              set             {                 _advancepayment = value;                 onpropertychanged("advancepayment");             }         }          private visibility _voidbuttonvisibility;         public visibility voidbuttonvisibility         {                         {                 return _voidbuttonvisibility;             }              set             {                 _voidbuttonvisibility = value;                 onpropertychanged("voidbuttonvisibility");             }         } }  public class advancepaymentsmodel : inotifypropertychanged     {         public int advanceid { get; set; }         public string paymentid { get; set; }         public decimal payment { get; set; }         public datetime paymentdate { get; set; }          private string _status;         public string status         {                         {                 return _status;             }              set             {                 _status = value;                 onpropertychanged("status");             }         }          private brush _brushobj;         public brush brushobj         {                         {                 return _brushobj;             }              set             {                 _brushobj = value;                 onpropertychanged("brushobj");             }         }          private advancepayment _advancepayment;         public advancepayment advancepayment         {                         {                 return _advancepayment;             }              set             {                 _advancepayment = value;                 onpropertychanged("advancepayment");             }         }          private visibility _voidbuttonvisibility;         public visibility voidbuttonvisibility         {                         {                 return _voidbuttonvisibility;             }              set             {                 _voidbuttonvisibility = value;                 onpropertychanged("voidbuttonvisibility");             }         }      } } 

after enabling debugging .net framework source code... see stackoverflow exception gets thrown in dispatcher class

 private void pushframeimpl(dispatcherframe frame)          {             synchronizationcontext oldsynccontext = null;             synchronizationcontext newsynccontext = null;             msg msg = new msg();               _framedepth++;              try              {                 // change clr synchronizationcontext compatable our dispatcher.                  oldsynccontext = synchronizationcontext.current;                 newsynccontext = new dispatchersynchronizationcontext(this);                 synchronizationcontext.setsynchronizationcontext(newsynccontext);                  try                 {                      while(frame.continue)                      {                         if (!getmessage(ref msg, intptr.zero, 0, 0))                              break;                          translateanddispatchmessage(ref msg); //*<--------- gets thrown here*                     }                       // if last frame exit after quit,                      // can dispose dispatcher.                      if(_framedepth == 1)                     {                          if(_hasshutdownstarted)                         {                             shutdownimpl();                         }                      }                 }                                   {                     // restore old synchronizationcontext.                      synchronizationcontext.setsynchronizationcontext(oldsynccontext);                 }             }                          {                 _framedepth--;                  if(_framedepth == 0)                  {                     // have exited frames.                      _exitallframes = false;                 }             }         }  

after crashing in dispatcher here stack trace:

    [managed native transition]       windowsbase.dll!system.windows.threading.dispatcher.pushframeimpl(system.windows.threading.dispatcherframe frame) line 2281 + 0x35 bytes    unknown     windowsbase.dll!system.windows.threading.dispatcher.pushframe(system.windows.threading.dispatcherframe frame) line 368 + 0x9 bytes  unknown     windowsbase.dll!system.windows.threading.dispatcher.run() line 327 + 0x34 bytes unknown >   presentationframework.dll!system.windows.application.rundispatcher(object ignore) line 2745 c#     presentationframework.dll!system.windows.application.runinternal(system.windows.window window) line 1841    c#     presentationframework.dll!system.windows.application.run(system.windows.window window) line 261 + 0x9 bytes c#     presentationframework.dll!system.windows.application.run() line 222 + 0x15 bytes    c#     urm.exe!urm.app.main() + 0x59 bytes c#     [native managed transition]       [managed native transition]       mscorlib.dll!system.appdomain.executeassembly(string assemblyfile, system.security.policy.evidence assemblysecurity, string[] args) + 0x6b bytes         microsoft.visualstudio.hostingprocess.utilities.dll!microsoft.visualstudio.hostingprocess.hostproc.runusersassembly() + 0x27 bytes       mscorlib.dll!system.threading.threadhelper.threadstart_context(object state) + 0x6f bytes        mscorlib.dll!system.threading.executioncontext.runinternal(system.threading.executioncontext executioncontext, system.threading.contextcallback callback, object state, bool preservesyncctx) + 0xa7 bytes       mscorlib.dll!system.threading.executioncontext.run(system.threading.executioncontext executioncontext, system.threading.contextcallback callback, object state, bool preservesyncctx) + 0x16 bytes       mscorlib.dll!system.threading.executioncontext.run(system.threading.executioncontext executioncontext, system.threading.contextcallback callback, object state) + 0x41 bytes         mscorlib.dll!system.threading.threadhelper.threadstart() + 0x44 bytes        [native managed transition]   

so after taking advice of @kellygendron , @david ended getting stackoverflow exception thrown in changetracker class

 internal override bool ismemberpendinggeneration(metadatamember keymember) {                     if (this.isnew && keymember.isdbgenerated) {                          return true;                     }                     // fk association has key member (should one)                     foreach (metaassociation assoc in type.associations) {                          if (assoc.isforeignkey) {      /*crashes here*/      int index = assoc.thiskey.indexof(keymember);                              if (index > -1) {                                  // must have reference other object know if side of                                 // association generated or not                                  object otheritem = null;                                 if (assoc.thismember.isdeferred) {                                     otheritem = assoc.thismember.deferredvalueaccessor.getboxedvalue(this.current);                                 }                                  else {                                     otheritem = assoc.thismember.storageaccessor.getboxedvalue(this.current);                                  }                                  if (otheritem != null) {                                     if (assoc.ismany) {                                          // can't pending generation value have same                                         // across many rows.                                         continue;                                     }                                      else {                                         standardtrackedobject trackedother = (standardtrackedobject)this.tracker.gettrackedobject(otheritem);                                          if (trackedother != null) {                                              metadatamember othermember = assoc.otherkey[index];                                             return trackedother.ismemberpendinggeneration(othermember);                                          }                                     }                                 }                             }                          }                     }                      return false;                  }             }          } 

the keymember seems can make out of partially available attributes location class (database table) , seems stuck on id column

i reading code incorrectly, in snippet looks newap.payment pointing may confusing serializer badly. again forgive me if i'm misreading, sleep deprived today.

foreach (advancepayment ap in a.advancepayments)     {         advancepayment newap = sp.advancepayments             .where(adv => adv.id == ap.id).singleordefault();         if (newap != null)         {             newap.payment = ap.payment;             ... 

if isn't case may want try breaking save multiple parts, example setting association null , specifying id. there similar case here may help... http://social.msdn.microsoft.com/forums/silverlight/en-us/d4438aaa-a916-4335-b182-ded75f162c2d/datacontextsubmitchanges-throws-stack-overflow-exception-on-rather-simple-insert


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -