I recently came across the above error for one of my Dynamics 365 Plugins…this blog talks about applying a quick fix.
While debugging our Plugin logic line by line to understand why it’s not working, observed this error for messages like RetrieveMultiple, Retrieve when I use any Organization Service call.
This was a .Net version downgrade issue caused by ILMerge as I downgraded one of the DLL to 4.6.2 version from 4.7.1. If you see this issue even without downgrading your DLL, you can use this fix.
After some research I came across this article and applied the same to my assembly which fixed the issue. Added these lines to my AssemblyInfo.cs class file..
To start with this scenario, this is one of the most commonly asked functionalities when we talk about of adding members to marketing list using an excel import.
In this scenario, we will make use of Connections entity and associate the marketing list to the contacts on creation of the connection…ok…let us give it a try….we will make use of plugin here….which runs on Create and on Post operation and calls the below method…
public void MarketingListImport()
{
Entity connectionER = (Entity)executionContext.InputParameters["Target"];
Entity marketingList = new Entity();
if (connectionER.Contains("record2id"))
{
EntityReference connectTo = connectionER.GetAttributeValue<EntityReference>("record2id");
EntityReference connectFrom = connectionER.GetAttributeValue<EntityReference>("record1id");
if (connectTo != null)
{
marketingList = organizationService.Retrieve(connectTo.LogicalName, connectTo.Id, new ColumnSet("type", "createdfromcode"));
}
if (connectTo.LogicalName == "list")//Marketing list
{
if (marketingList.Contains("type") && marketingList.GetAttributeValue<bool>("type") == false)
{
if (connectFrom.LogicalName == "contact" && marketingList.Contains("createdfromcode") && marketingList.GetAttributeValue<OptionSetValue>("createdfromcode").Value == 2)//Resident
{
// Add a list of contacts to the marketing list.
var addMemberListReq = new AddListMembersListRequest
{
MemberIds = new[] { connectFrom.Id },
ListId = connectTo.Id
};
organizationService.Execute(addMemberListReq);
tracingService.Trace("Contacts with GUIDs \r\n\t{{{0}}} is added to the list.",
connectFrom.Id);
}
else
{
throw new InvalidPluginExecutionException("Marketing list should be targeted at contact and contacts can be imported");
}
}
else
{
throw new InvalidPluginExecutionException("Members cannot be imported into a Dynamic Marketing list, please select a static marketing list and try again");
}
}
}
}
}
Once you were done writing the code, next step is to test the functionality…for this we will use the following template.
Import this template from the imports area under settings in your Dynamics 365…boom….the contacts in the template will be added to your Static Marketing List.