• 0

[C#] linq exception handling in a query?


Question

If you get an exception while trying to make a nested query a dictionary that states a same key has already been added is there a way of actually seeing the key that is attempted to be added? In the debugger it just says the error of an key already exists with a stack trace of (I took out the actual path names):

   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at a.MainWindow.<>c__DisplayClass4a.<refreshClientLocks>b__14(DataRow acc_dr) in a\MainWindow.xaml.cs:line 301
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at a.MainWindow.<refreshClientLocks>b__12(<>f__AnonymousType0`2 <>h__TransparentIdentifier5) in a\MainWindow.xaml.cs:line 299
   at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
   at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()

9 answers to this question

Recommended Posts

  • 0

yes, the inner exception is null, which makes sense b/c it's throwing the exception since a key is being added to a dictionary that already has that key definition. Since it is in a query I can't see which (to my knowledge at least)

key is attempting to be added twice.

  • 0

Not sure how to break this into smaller queries without compromising performance at a terrible rate:

var clientQuery = from DataRow client_dr in this.gl_aeiMgr.ClientsDataSet.Tables[this.gl_aeiMgr.ClientsTbl].Rows
                                                  let clientId = client_dr.Field<string>("userAccessId                                                let accList = (from DataRow acc_dr in this.gl_aeiMgr.ClientsAccDataSet.Tables[this.gl_aeiMgr.ClientsAccTbl].Rows
                                                                 where acc_dr.Field<string>("clientID clientId
                                                                 select new
                                                                 {
                                                                     AccId = acc_dr.Field<string>("userAccessId                                                                    AccDefObj = new AccDef(acc_dr.Field<string>("userAccessIdlientId, acc_dr.Field<int>("acc_numAccType)Enum.Parse(typeof(AccType), acc_dr.Field<string>("acc_type                                                                         (AccBillCycle)Enum.Parse(typeof(AccBillCycle), acc_dr.Field<string>("accScheduleType                                                                         (from DataRow benf_dr in this.gl_aeiMgr.ClientsBenfDataDet.Tables[this.gl_aeiMgr.ClientsBenfTbl].Rows
                                                                          let benfAccId = benf_dr.Field<string>("userAccessId                                                                        where benf_dr.Field<string>("benfAccId acc_dr.Field<string>("userAccessId                                                                        select new BenfDef(benf_dr.Field<string>("userAccessIdenfAccId, benf_dr.Field<string>("benfFirstNamebbenf_dr.Field<string>("benfLastNamebbenf_dr.Field<string>("benfMiddleInit                                                                             benf_dr.Field<string>("benfSSNbbenf_dr.Field<DateTime>("benfDOBbbenf_dr.Field<double>("benfPercentbbenf_dr.Field<string>("benfAddrStreet                                                                             benf_dr.Field<string>("benfAddrCityGlobals.USPSStateCodes)Enum.Parse(typeof(Globals.USPSStateCodes), benf_dr.Field<string>("benfAddrState                                                                              benf_dr.Field<string>("benfAddrZipCodebbenf_dr.Field<string>("benfAddrCountrybbenf_dr.Field<string>("benfPPhonePhoneContactType)Enum.Parse(typeof(PhoneContactType), benf_dr.Field<string>("benfPPhoneType")))).ToDictionary(oenfId, o =&gt; o),
                                                                         (from DataRow benf_dr in this.gl_aeiMgr.ClientsSBenfDataSet.Tables[this.gl_aeiMgr.ClientsSBenfTbl].Rows
                                                                          let benfAccId = benf_dr.Field<string>("userAccessId                                                                        where benf_dr.Field<string>("benfAccId acc_dr.Field<string>("userAccessId                                                                        select new BenfDef(benf_dr.Field<string>("userAccessIdenfAccId, benf_dr.Field<string>("benfFirstNamebbenf_dr.Field<string>("benfLastNamebbenf_dr.Field<string>("benfMiddleInit                                                                             benf_dr.Field<string>("benfSSNbbenf_dr.Field<DateTime>("benfDOBbbenf_dr.Field<double>("benfPercentbbenf_dr.Field<string>("benfAddrStreet                                                                             benf_dr.Field<string>("benfAddrCityGlobals.USPSStateCodes)Enum.Parse(typeof(Globals.USPSStateCodes), benf_dr.Field<string>("benfAddrState                                                                              benf_dr.Field<string>("benfAddrZipCodebbenf_dr.Field<string>("benfAddrCountrybbenf_dr.Field<string>("benfPPhonePhoneContactType)Enum.Parse(typeof(PhoneContactType), benf_dr.Field<string>("benfPPhoneType")))).ToDictionary(oenfId, o =&gt; o),
                                                                         HelperUtils.ToObservableCollection&lt;PmtDef&gt;((from DataRow pmt_dr in this.gl_aeiMgr.ClientsPmtDSet.Tables[this.gl_aeiMgr.ClientsPmtTbl].Rows
                                                                                                                     where pmt_dr.Field<string>("accId acc_dr.Field<string>("userAccessIdmp;&amp; pmt_dr.Field<bool>("pmtIsExp false
                                                                                                                     select new PmtDef(pmt_dr.Field<string>("userAccessIdppmt_dr.Field<DateTime>("pmtEffDateppmt_dr.Field<double>("pmtAmt                                                                                                                    false, pmt_dr.Field<bool>("pmtIsStmtppmt_dr.Field<DateTime>("pmtExpDateppmt_dr.Field<string>("pmtChkNum"))).AsEnumerable<PmtDef>, null, null,
                                                                                                                     (from DataRow certList_dr in this.gl_aeiMgr.ClientsCertListDSet.Tables[this.gl_aeiMgr.ClientsCertLstTbl].Rows
                                                                                                                      where certList_dr.Field<string>("accID acc_dr.Field<string>("userAccessId                                                                                                                    select new CertDef(certList_dr.Field<string>("userAccessIdccertList_dr.Field<int>("certNumccertList_dr.Field<double>("certAmt"))).GroupBy(oertAmt).ToDictionary(o =&gt; o.Key, o =&gt; o.ToList&lt;CertDef&gt;()),
                                                                                                                          (from DataRow note_dr in this.gl_aeiMgr.ClientsNotesDSet.Tables[this.gl_aeiMgr.ClientsNotesTbl].Rows
                                                                                                                           where note_dr.Field<string>("accId acc_dr.Field<string>("userAccessId                                                                                                                         select new NoteDef(note_dr.Field<string>("noteNumnnote_dr.Field<string>("noteNumnnote_dr.Field<DateTime>("noteDateEff                                                                                                                              note_dr.Field<DateTime>("noteDateExpAccBillCycle)Enum.Parse(typeof(AccBillCycle), note_dr.Field<string>("noteBillCyclerue), note_dr.Field<bool>("noteIsPaidnnote_dr.Field<double>("notePmt"))).ToDictionary(ooteId, o =&gt; o),
                                                                                                                                   (from DataRow rel_dr in this.gl_aeiMgr.ClientsRelConDSet.Tables[this.gl_aeiMgr.ClientsRelConTbl].Rows
                                                                                                                                    where rel_dr.Field<string>("accId acc_dr.Field<string>("userAccessId                                                                                                                                  select new RelContactDef(rel_dr.Field<string>("userAccessIdrrel_dr.Field<string>("fNamerrel_dr.Field<string>("lNamerrel_dr.Field<string>("addrStreetrrel_dr.Field<string>("addrCity                                                                                                                                       (Globals.USPSStateCodes)Enum.Parse(typeof(Globals.USPSStateCodes), rel_dr.Field<string>("addrStaterue), rel_dr.Field<string>("addrZipCode                                                                                                                                       rel_dr.Field<string>("addrCountryrrel_dr.Field<string>("phonerrel_dr.Field<string>("companyrrel_dr.Field<string>("email"))).ToDictionary(oelContactId, o =&gt; o),
                                                                                                                                            (from DataRow frm_dr in this.gl_aeiMgr.ClientsAccFormsDset.Tables[this.gl_aeiMgr.ClientsAccFormsTbl].Rows
                                                                                                                                             where frm_dr.Field<string>("clientsAccID acc_dr.Field<string>("userAccessId                                                                                                                                           select new FrmDetailLstDef(frm_dr.Field<string>("userAccessIdffrm_dr.Field<string>("formNameFrmStatus)Enum.Parse(typeof(FrmStatus), frm_dr.Field<string>("formStatusrue), frm_dr.Field<DateTime>("formDateCreatedffrm_dr.Field<string>("formLocation"))).ToDictionary(ormId, o =&gt; o))
                                                                 }).ToDictionary(o =&gt; o.AccId, o =&gt; o.AccDefObj)
                                                  select new ClientDef(clientId, client_dr.Field<string>("fNamecclient_dr.Field<string>("middleInitcclient_dr.Field<string>("lName                                                     client_dr.Field<string>("ssncclient_dr.Field<string>("pPhone1Numclient_dr.Field<string>("pPhone1Ext null) ? client_dr.Field<string>("pPhone1Ext"", (client_dr.Field<string>("pPhone2Num null) ? client_dr.Field<string>("pPhone2Num"",
                                                      (client_dr.Field<string>("pPhone2Ext null) ? client_dr.Field<string>("pPhone2Ext"", ClientMgr.ConvertPhoneTypeFromStr(client_dr.Field<string>("pPhone1Type                                                      ClientMgr.ConvertPhoneTypeFromStr(client_dr.Field<string>("pPhone2Typeclient_dr.Field<string>("mAddrStreetlientMgr.ConvertStateCodeFromStr(client_dr.Field<string>("mAddrState                                                      client_dr.Field<string>("mAddrZipCodecclient_dr.Field<string>("mAddrCitycclient_dr.Field<string>("mAddrCountryccList, client_dr.Field<string>("mFaxContactcclient_dr.Field<string>("pEmailAddrcclient_dr.Field<DateTime>("clientDOB                                                     client_dr.Field<int>("ppmNumcclient_dr.Field<double>("ppmInvestNum

  • 0

the bug was not within the query, it was another piece of code that was pointing to the wrong table. I didn't catch it b/c the only difference between the two datasets/table names is one has an S in the middle of it and one does not. So it was grabbing the information out of the wrong table. Thanks for the help guys!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Movavi Video Editor 25.9.0 by Razvan Serea With Movavi Video Editor, you can either enhance your video files with two or three simple steps, or turn them into something completely new. Create your own movies using multiple filters, transitions, and special effects: show multiple videos on one screen with the Picture in picture effect or change the background with the Chroma Key effect, imitate the camera zoom or make your video look like an old-style movie. Adjust video parameters such as brightness, contrast and colors. Stabilize shaky footage, improve video quality and remove defects. Create video presentations, tutorials or educational videos: add titles and record your own narration to create a video with voiceover. Import video from any source: TV-tuner, webcam, camcorder, or VHS. Drop multiple media files onto a timeline and let your imagination do the rest! Features at a glance: Video and audio editing on a timeline Edit, enhance videos Add background music Apply titles and effects Image quality improvement Hollywood-worthy effects High-grade titles and fades Digitize VHS tapes, record video from TV tuners Stabilize any shaky sections Support for a wide range of formats Prepare your videos for uploading to YouTube, Facebook, Vimeo, or any other website New in Movavi Video Editor 2025: Revamped timeline for easier editing The new timeline is now clearer and more streamlined. Get your projects done faster and have more fun with anything – from short vids for socials to longer family movies. Frame-precise cuts in a click Give your videos a sharper look with the new Blade tool. Easily make precise cuts and create eye-catching montages like your favorite bloggers. Pro-quality color correction Get next-level color correction with the same simplicity. Boost colors in a snap and make more viewers fall in love with your videos. AI motion tracking Enhance reality in your videos with additional moving graphics. Just click, and AI will quickly attach any photos, videos, emojis, or memes to objects in your footage. Perfect-match overlay effects Now each overlay effect has 13 blending modes to choose from. Try each of them with the press of a button and pick the one that fits your video perfectly. Best video effects – at your fingertips Create awesome videos in any style with our huge collection of professionally designed effects. Now you can try them all right away, right in the app. Movavi Video Editor 25.9.0 changelog: New Copy effects from one clip to another in a snap. Just right-click the clip → Clip effects → Copy effects. Then right-click again to paste. Try it once, and it might just become your new favorite feature. Improvements Enjoy speedier, smoother previews – now up to 20% faster! Hover over any clip to see the difference. Especially handy when you’ve got a load of clips on the timeline. Speed up editing with new keyboard shortcuts. Ctrl + Z to undo, Ctrl + scroll to zoom the timeline. You’ll find the full list in the Help menu. Fixed issues Some under-the-hood improvements that’ll be useful for faster content creation. Download: Movavi Video Editor Plus 25.9.0 | 5.1 MB (Shareware) View: Movavi Video Editor Plus Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I don't disagree, but I am also not absolving Microsoft. Data protection is the user's responsibility AND OneDrive shouldn't arbitrarily lockout paying users with no way to get support. Again, both statements can be true at the same time. I doubt you mean to imply it is okay for companies to violate their SLAs and screw over their customers. Assuming you don't think that, then we have no disagreement my friend.
    • Also, Microsoft locks Windows 11 user out, shows how easy losing data from forced encryption is The reddit post has nothing to do with Windows 11 or 'Forced' Encryption, at all, reading the thread a guy has uploaded a load of files, deleted the source, tripped the ToS for some reason and been locked out The guy could have been using Windows 7 box with no drive encryption. A more accurate headline would be User with no backup looses data
    • I've been using Microsoft cloud storage since before it was named OneDrive. Though typically only upload the following items. Game Screenshots of like crashes if its a driving game, or occasionally a Video recorded with GameDVR All Purchased Music from former Microsoft App store when they offered music during Windows 8.1, Xbox/Groove Music days, in additon to the 30 Free Albums Christmas 2024 for using a Windows Phone at the time. Of course everything is also backed up on 3 external hard drives as well. and albums that would be hard to replace, also uploaded to GoogleDrive, ((though can't upload all of it to Google drive, as not enough space there to lol)) Been using Microsoft Hotmail & Outlook email ever since first released Hotmail originally signed up April 1998 during high school class Outlook.com email converted to when first launched many years ago
  • Recent Achievements

    • Week One Done
      Rhydderch earned a badge
      Week One Done
    • Experienced
      dismuter went up a rank
      Experienced
    • One Month Later
      mevinyavin earned a badge
      One Month Later
    • Week One Done
      rozermack875 earned a badge
      Week One Done
    • Week One Done
      oneworldtechnologies earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      699
    2. 2
      ATLien_0
      272
    3. 3
      Michael Scrip
      214
    4. 4
      +FloatingFatMan
      186
    5. 5
      Steven P.
      144
  • Tell a friend

    Love Neowin? Tell a friend!