delegateas/XrmFramework

I cannot access Appointment attendees through early-bound code

candelegate opened this issue · 3 comments

I'm having some issues accessing certain fields on the Appointment entity through a plugin using early-bound code

The plugin is running on PreOperation Create, and triggers just fine.

I'm trying to access fields on the Organizer/RequiredAttendees/OptionalAttendees fields:
image

This is the code I'm running
image

which calls this method:
image

Plugin trace:
image

Based on traces, I can see that the RequiredAttendees enumerable does contain the correct number of elements, but whenever I try to iterate through the RequiredAttendees, the first element is just null, and I get a NullReferenceException.

Using late-bound code:
image

Works perfectly. I can access the addressused field and get the correct value.

Plugin trace:
image

The issue is with XrmContext. Specifically with GetEntityCollection<T> in XrmExtensions.cs which contains an invalid cast by attempting to cast Entity objects to ActivityParty through the as keyword instead of using ToEntity<ActivityParty>(), which results in all the elements being converted to null.

With the fix, I am getting the following error (taken from plugin trace viewer)

System.ServiceModel.FaultException1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Type 'IsIT.CRM.D365.Plugins.BusinessDomain.ExtendedEntity2[IsIT.CRM.D365.Plugins.BusinessDomain.EmptyEnum,IsIT.CRM.D365.Plugins.BusinessDomain.EmptyEnum]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types. (Fault Detail is equal to Exception details:
ErrorCode: 0x80040224
Message: Type 'IsIT.CRM.D365.Plugins.BusinessDomain.ExtendedEntity`2[IsIT.CRM.D365.Plugins.BusinessDomain.EmptyEnum,IsIT.CRM.D365.Plugins.BusinessDomain.EmptyEnum]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
TimeStamp: 2022-08-09T07:10:13.9701338Z
OriginalException: Internal
ExceptionSource: Internal

).

The above error turned out to be related to passing List<AcivityParty> to a Shared Variable. I'm unsure if that should also be supported, but it is not related to this issue, which should still be resolved by the linked fix.