简体   繁体   English

System.Collections.Generic.KeyNotFoundException动态CRM C#查找字段错误

[英]System.Collections.Generic.KeyNotFoundException Dynamics CRM C# lookup field error

I am trying to create a new record in Dynamics CRM using C#. 我正在尝试使用C#在Dynamics CRM中创建新记录。

Below is the code that I am using: 下面是我正在使用的代码:

 Entity Record = new Entity("new_edRecord");
 Record["new_year"] = "2100";
 Record["new_school"] = new EntityReference("new_school",new Guid("8ba53949-3947-e445-876c-001dd8b71c19"));
 Record["new_gradelevel"] = "100000018";
 organizationProxy.Create(Record);

When I execute this, I get the below error: 执行此操作时,出现以下错误:

Unexpected exception from plug-in (Execute): Department.EdRecord.RecordCreate: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. 插件异常(执行):Department.EdRecord.RecordCreate:System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键。

I double checked to see if a school exist with the GUID by visiting the below url: 我通过访问以下网址仔细检查了GUID是否存在一所学校:

https://crm.site.com/orgname/api/data/v8.0/new_schools(8ba53949-3947-e445-876c-001dd8b71c19)

and this brought a result. 这带来了结果。 Not sure what I am missing here. 不知道我在这里想念的是什么。

If new_gradelevel is an Optionset type of field, following should be the code-: 如果new_gradelevel是现场的Optionset类型,下面应该是代码- :

Record["new_gradelevel"] = new OptionSetValue(100000018);

Also, can you confirm the data type of new_year is String . 另外,您是否可以确认new_year的数据类型为String

Hope it helps. 希望能帮助到你。

It is a common convention to name CRM lookup fields as the entity name with id appended. 将CRM查找字段命名为带有id的实体名称是一种常见约定。

Is it possible that Record["new_school"] should be Record["new_schoolid"] ? Record["new_school"]应该是Record["new_schoolid"]吗?

OR: 要么:

Perhaps the value 100000018 does not exist in the Record["new_gradelevel"] optionset. 也许在Record["new_gradelevel"]不存在值100000018 Maybe comment out that line and see what happens. 也许注释掉那条线,看看会发生什么。

Like other answers suggested, verify all the field names/schema names for its correctness. 像建议的其他答案一样,验证所有字段名称/方案名称的正确性。

You can do trial & error by commenting out the fields one by one and execute this code to find out the buggy line. 您可以通过逐一注释掉这些字段并执行此代码来找出错误的代码行,从而进行反复试验。

Finally, (this will be my first troubleshooting step) cross check if you have any other plugins on post create of new_edrecord entity or associate of new_school entity. 最后,(这将是我的第一个故障排除步骤)交叉检查,如果您有任何后其他插件创建的new_edrecord实体或副new_school实体。 That synchronous plugin may throw this KeyNotFoundException error but bubble here. 该同步插件可能会抛出此KeyNotFoundException错误,但在此冒泡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#, System.Collections.Generic.KeyNotFoundException'发生在 mscorlib.dll - C#, System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll System.Collections.Generic.KeyNotFoundException: '字典中不存在给定的键。' C# 窗口应用程序 - System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.' C# windows application System.Collections.Generic.KeyNotFoundException似乎没有原因 - System.Collections.Generic.KeyNotFoundException For Seemingly No Reason Windows Phone中的System.Collections.Generic.KeyNotFoundException - System.Collections.Generic.KeyNotFoundException in Windows Phone Facebook MVC应用程序演示中的System.Collections.Generic.KeyNotFoundException - System.Collections.Generic.KeyNotFoundException on Facebook MVC Application demo System.Collections.Generic.KeyNotFoundException:给定的键不在字典中 - System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary "为什么 LINQ Sum() 抛出“System.Collections.Generic.KeyNotFoundException”?" - Why LINQ Sum() throws "System.Collections.Generic.KeyNotFoundException"? System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键“Item” - System.Collections.Generic.KeyNotFoundException : The given key 'Item' was not present in the dictionary System.Collections.Generic.KeyNotFoundException:字典中不存在给定键“All” - System.Collections.Generic.KeyNotFoundException: The given key 'All' was not present in the dictionary 您能解释一下此System.Collections.Generic.KeyNotFoundException吗? - Can you explain this System.Collections.Generic.KeyNotFoundException?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM