'OutputParameters must contain a property called 'BusinessEntityCollection' of type Microsoft.Xrm.Sdk.EntityCollection for SDK message RetrieveMultiple

Creating a plugin for virtual entity, while trying to parse an EntityCollection to PluginExecutionContext in Microsoft.Xrm.Sdk it fails with message

Error

"message":"OutputParameters must contain a property called 'BusinessEntityCollection' of type Microsoft.Xrm.Sdk.EntityCollection for SDK message RetrieveMultiple",

Code is something like

            string data = await GetData(localcontext);
            
            var desrlzdData = JsonConvert.DeserializeObject<CustomEntity[]>(data);
            EntityCollection collection = new EntityCollection();
            foreach (var d in desrlzdData)
            {
                collection.Entities.Add(mapper(d));
            }

            // Add result to output parameters
            localcontext.PluginExecutionContext.OutputParameters["BusinessEntityCollection"] = collection;



Solution 1:[1]

The problem was with async code, I was not doing await at one of the place. So The BusinessEntityCollection was not getting populated but the error message is bit misleading.

Solution 2:[2]

Modify the last time in this:

localcontext.PluginExecutionContext.OutputParameters["EntityCollection"] = collection;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arnav Karforma
Solution 2 Henk van Boeijen