Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 1 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
We're using Microsoft.CrmSdk.CoreAssemblies 18.104.22.168 with earlier bind, when retriving record from entity collection, sometimes we're getting:
xxx.xxx.Crm.Api.PartyController+<>c__DisplayClass3_0.<DetailsAsync>b__0()] Unhandled exception System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.MergeEntity(Entity entity) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Linq.Enumerable.<CastIterator>d__97`1.MoveNext() at Microsoft.Xrm.Sdk.Linq.PagedItemCollection`1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at xxx.Crm.BusinessLogic.PartyContext.Get(Identifier identifier) in D:\a\1\s\Application\Vxxx.xxx.Crm.BusinessLogic\PartyContext.cs:line 67 at xxx.Crm.Api.PartyController.<>c__DisplayClass3_0.<DetailsAsync>b__0() in D:\a\1\s\Application\xxx.Crm\Api\PartyController.cs:line 76
The query is quite simple, like: _CrmContext.Parties.FirstOrDefault(p => p.xx_name == "KDIE3242"), where _CrmContext is an instance of early bind Crm class we generated using a MS tool from our
Dynamic 365 CRM, it contains all the entities in our CRM. We're using it in a Web API service, getting this error randomly. Any idea why?
Any suggestion is appreciated.
FirstOrDefault will return first entity record if present and null if no entity record present.
So when it return default which is nothing but null and then you are trying to find p.xx_name which does not exist so you get error.
To fix this issue you should have below check condition.
Entity Parties= _CrmContext.Parties.FirstOrDefault;//Change Entity to respective early bound entity class name
if (Parties!= null)
then perform your operation;
Thank you for your reply.
The Parties is a main entity in our CRM, we know we have thousands of records in Parties, why do we need check if Parties is not null? It should never null, or is there any special cases that an Entity of CRM Context will be null? Can't think of it.
What I'm thinking is because this query almost performed for every request made to our service for all the endpoints, is this a co-current issue since the requests from different endpoint are hitting same entity and try to query it at same time? for performance reason, we injected CRM Context as SingleInstance when service start.
Business Applications communities