• 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

    • XRECODE3 1.166 by Razvan Serea xrecode3 is a converter and audio-grabber which allows you to convert from mp3, mp2, wma, aiff, amr, ogg, flac, ape, cue, ac3, wv, mpc, mid, cue ,tta, tak, wav, wav(rf64), dts, m4a, m4b, mp4, ra, rm, aac, avi, mpg, vob, mkv, mka, flv, swf, mov, ofr, wmv, divx, m4v, spx, 3gp, 3g2, m2v, m4v, ts, m2ts, adts, shn, tak, xm, mod, s3m, it, mtm, umx, mlp to m4a, alac, ape, flac, mp3, mp4 (using NeroAAC), ogg, raw, wav, wav(rf64), wma, WavPack, mpc, mp2, Speex, ofr, ac3, aiff, tak, snd and Shorten formats. Command Line parameters are supported. XRECODE3 features: Works on XP, Vista, Windows 7, Windows 8, 10 32/64 bit versions and under Wine. Parallel conversion by utilizing power of multi-core CPUs. Support of embedded CUE sheets (for FLAC, WavPack, APE and TAK files). Support of mp4, mka chapters (can split mp4, mka by chapters to any supported format). Built-in Metadata editor with Cover Art support. Has support for LossyWav. Supports portable mode. Merge input files to one large audio file and create CUE sheet. Converting to many formats at once using "Multiple" output mode. Grabbing of multi-channel Audio CDs to the desired format at once. Informative and resizable UI suited even for netbooks. Extracting audio from flv, avi, mov etc. video files (multiple audio streams are supported). Can export/import Metadata to/from external file. Support for 24/32bit audio files. Multilanguage support. Currently program is available in Dutch, English, French, Japanese, Korean, Polish, Russian, Hungarian, Italian, Spanish, Spanish Traditional, Swedish, Brazilian Portuguese, German, Finnish, Bulgarian, Czech, Danish and Chinese (simplified) languages. What's new in XRECODE3: Native 64bit support. Added support for DSD/DST and DFF formats (including handling of SACD ISOs). Added option to extract audio without transcoding. Added option to encode several files to one multi-channel file. Added option to split file into individual track-per-channel for all available output formats. Added option to merge files per folder. Output and Metadata settings are now output format specific. Enhanced Metadata settings. Added support for multiple Cover pictures in Metadata editor. Added 32bit int/float output for formats which support them (e.g. WAV). Added dithering option in Output Settings. Added option to use EBUR128 in Normalize. Added option to Album Mode Normalize. Added option to configure Matrices under Output Settings. Added more output file pattern elements. Tabbed UI. CUE files are now displayed more nicely. Enhanced Shell Extension. XRECODE3 1.166 changelog: fixed crash when opening a file without an audio stream. fixed issue when applying tempo to some files. fixed issue with handling of some .ofr files. Download: XRECODE3 v1.166 (64-bit) | Portable | ~30.0 MB (Shareware) Download: XRECODE3 v1.166 (32-bit) | Portable Link: XRECODE3 Homepage | XRECODE3 Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • OBS Studio 31.1.0 Beta 2 by Razvan Serea OBS Studio is software designed for capturing, compositing, encoding, recording, and streaming video content, efficiently. It is the re-write of the widely used Open Broadcaster Software, to allow even more features and multi-platform support. OBS Studio supports multiple sources, including media files, games, web pages, application windows, webcams, your desktop, microphone and more. OBS Studio Features: High performance real time video/audio capturing and mixing, with unlimited scenes you can switch between seamlessly via custom transitions. Live streaming to Twitch, YouTube, Periscope, Mixer, GoodGame, DailyMotion, Hitbox, VK and any other RTMP server Filters for video sources such as image masking, color correction, chroma/color keying, and more. x264, H.264 and AAC for your live streams and video recordings Intel Quick Sync Video (QSV) and NVIDIA NVENC support Intuitive audio mixer with per-source filters such as noise gate, noise suppression, and gain. Take full control with VST plugin support. GPU-based game capture for high performance game streaming Unlimited number of scenes and sources Number of different and customizable transitions for when you switch between scenes Hotkeys for almost any action such as start or stop your stream or recording, push-to-talk, fast mute of any audio source, show or hide any video source, switch between scenes,and much more Live preview of any changes on your scenes and sources using Studio Mode before pushing them to your stream where your viewers will see those changes DirectShow capture device support (webcams, capture cards, etc) Powerful and easy to use configuration options. Add new Sources, duplicate existing ones, and adjust their properties effortlessly. Streamlined Settings panel for quickly configuring your broadcasts and recordings. Switch between different profiles with ease. Light and dark themes available to fit your environment. …and many other features. For free. At all. OBS Studio 31.1.0 Beta 2 changelog: Adjusted volume mixer styling on Classic theme [Warchamp7] Enabled font size option for macOS in appearance settings [gxalpha] Fixed an issue in Beta 1 where the projector menu for disabled preview was incorrect [Warchamp7] Fixed an issue in Beta 1 where opening appearance settings would enable the Apply button [Warchamp7] Fixed an issue in Beta 1 with menu bar padding [Warchamp7] Fixed an issue in Beta 1 with cut off text in Auto-Configuration Wizard [shiina424] Fixed an issue in Beta 1 with tab padding for new UI Appearance options [COOLIGUAY] Fixed an issue in Beta 1 where AMF AV1 B-frames did not work when using CQP [rhutsAMD] Download: OBS Studio 31.1.0 Beta 2 | Portable | ~200.0 MB (Open Source) View: OBS Studio Homepage | Other Operating Systems | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Brave 1.79.119 by Razvan Serea Brave Browser is a lightning-fast, secure web browser that stands out from the competition with its focus on privacy, security, and speed. With features like HTTPS Everywhere and built-in tracker blocking, Brave keeps your online activities safe from prying eyes. Brave is one of the safest browsers on the market today. It blocks third-party data storage. It protects from browser fingerprinting. And it does all this by default. Speed - Brave is built on Chromium, the same technology that powers Google Chrome, and is optimized for speed, providing a fast and responsive browsing experience. Brave Browser also features Brave Rewards, a system that rewards users with Basic Attention Tokens (BAT) for viewing opt-in ads. This innovative system provides an alternative revenue model for content creators and a way to support the Brave community. Brave 1.79.119 changelog: [Security] Added a conditional host check in binding handlers as reported on HackerOne by newfunction. (#46181) Fixed procedural filters not matching against dynamically added child elements. (#46208) Upgraded Chromium to 137.0.7151.68. (#46515) Download: Brave Browser 64-bit | 1.2 MB (Freeware) Download: Brave Browser 32-bit View: Brave Homepage | Offline Installers | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Here's every new AI feature Apple rumored to announce at WWDC 2025 by Hamid Ganji While Apple's WWDC event kicks off on June 9, Bloomberg's Mark Gurman has released a detailed report about every new AI feature Apple might unveil at the event. One of the most notable AI-related announcements at this year's WWDC is the Translate app. According to Gurman, Apple aims for a "systemwide push into translation" in iOS 26 while giving an AI boost to its Translate app. The app is expected to function as an Apple Intelligence feature and will be integrated into the operating system. The Translate app, initially designed for translating text, voice, and conversations, will focus on live translation of phone calls and text messages in iOS 26. Gurman also added that Apple is working on translating live conversations for AirPods wearers. Apple has a slew of AI-related announcements at WWDC 2025. For example, the iPhone maker reportedly allow third-party developers to access its Foundation Models to build AI features. Foundation Models are a suite of generative AI models behind Apple Intelligence features, including text summarization, Writing Tools, and Genmoji. Speaking of Genmoji, Gurman claims the feature in iOS 26 allows users to create a Genmoji by combining a pair of existing standard emoji. The Shortcuts app in iOS 26 also gets a touch of Apple Intelligence, allowing users to seamlessly create quick shortcuts for various actions using AI. Apple has seemingly prepared an upgraded version of the Foundation Models for both on-device and cloud use. These models will be announced at the WWDC, but developers can only access the on-device version. Today's report suggests that Apple will also introduce a new version of Xcode that taps into third-party LLMs. The feature is being tested internally using Claude models. According to Gurman, Apple's revamped Calendar app won't make it to this year's software and will debut on iOS 27 and macOS 27. Moreover, Apple's new Health app with AI recommendations has hit delays and won't be announced at the upcoming WWDC. The revamped app will be released at the earliest by the end of next year. Apple's battery optimization feature, which uses AI to save power on iPhones, may debut later this year with the iPhone 17 Air. Finally, Gurman says Apple is in talks with Google to add Gemini to iPhones as an alternative to OpenAI's ChatGPT. However, the collaboration won't be announced at this year's WWDC. Companies await the final ruling on Google's search deal with Apple.
  • Recent Achievements

    • One Year In
      Vladimir Migunov earned a badge
      One Year In
    • One Month Later
      daelos earned a badge
      One Month Later
    • Week One Done
      daelos earned a badge
      Week One Done
    • Mentor
      Karlston went up a rank
      Mentor
    • One Month Later
      EdwardFranciscoVilla earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      494
    2. 2
      snowy owl
      252
    3. 3
      +FloatingFatMan
      250
    4. 4
      ATLien_0
      225
    5. 5
      +Edouard
      183
  • Tell a friend

    Love Neowin? Tell a friend!