dynamics crm 365 plugin exception值不能为null,使用早期绑定类将记录添加到输出参数实体集合

问题描述 投票:0回答:1

我有一个插件,它在检索多个消息(后期操作阶段)上的自定义实体上运行。

我正在尝试将其他实体添加到输出实体集合中(出于只读目的,用户不会编辑任何显示的记录)。早期绑定类是使用SDK中的CrmSvcUtil生成的。

 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:值不能为null。参数名称:value

enter image description here

dynamics-crm microsoft-dynamics dynamics-crm-2013 dynamics-crm-online
1个回答
0
投票

在线results.Add(...)你试图将Entity添加到EntityCollection,这是不可能的。你必须通过访问EntityDataCollection<Entity>添加到results.Entities

因此,我怀疑你的代码部分是否正常工作,无论你在哪里尝试添加预定义的实体newItem,以及你在尝试使用.Add(new {...})添加你的实体的地方。

© www.soinside.com 2019 - 2024. All rights reserved.