1
votes

I have a plugin that runs on a custom entity on the retrieve multiple message (post operation stage).

I am trying to add additional entities to the output entity collection (for read only purposes, the user is not going to edit any of the displayed records). The early bound classes is generated using the CrmSvcUtil from the SDK.

 var retrievedResult= (EntityCollection)context.OutputParameters["BusinessEntityCollection"];
 var results = new List<Entity>();

// THIS WORKS ------------------------------------
var newItem = new Entity("new_testentity");
newItem.Id = Guid.NewGuid();
newItem["new_name"] = "Test1";
results.Add(newItem);
//------------------------------------------------

// THIS IS NOT WORKING - throws exeption as shown below the code snippet
//results.Add(new new_testentity
//{
//   Id = Guid.NewGuid(),
//   new_name = "Test1"
//})


// Add new entities to output collection
retrievedResult.Entities.AddRange(results);

// This appears in the log, which mean the exception has not occurred yet
_trace.Trace("End of post operation...");

System.ArgumentNullException: Value cannot be null. Parameter name: value

enter image description here

1
What Line is the error actually occurring on? - Daryl
No error is thrown in the post operation stage of the plugin at all. If I place a trace as the final line, it reaches it successfully. - noobie
So when are you getting an exceptional then? Is it in the trace log? - Daryl
Through the UI, when I navigate to that specific entity and open the list view for all active items. It does not render the list, but has a download log link to the error. - noobie
You might need to call ToEntity<Entity>() on the EarlyBound classes... - Daryl

1 Answers

0
votes

In the line results.Add(...) you're trying to add an Entity to an EntityCollection which isn't possible. You have to add an Entity to a DataCollection<Entity> by accessing results.Entities.

I therefore doubt either of your sections of code are working, both where you're trying to add the pre-defined Entity newItem and where you're trying to add your Entity inline with .Add(new {...}).