System.Collections.Generic.KeyNotFoundException Dynamics CRM C# lookup field error
I am trying to create a new record in Dynamics CRM using C#.
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.
I double checked to see if a school exist with the GUID by visiting the below url:
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.
c# dynamics-crm crm dynamics-crm-2015
add a comment |
I am trying to create a new record in Dynamics CRM using C#.
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.
I double checked to see if a school exist with the GUID by visiting the below url:
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.
c# dynamics-crm crm dynamics-crm-2015
1
Have you set any breakpoints to see which line is failing in your example? The provided URL, uses "new_schools", and you are using "new_school"
– Ryan Wilson
Nov 13 at 18:35
Yeah, It fails if I add the new_school. it's a mandatory field so it needs to be specified. And the new_schools is used in the upper because CRM uses plural name for rest api
– Vignesh Subramanian
Nov 13 at 18:44
I would wager that "new_school" is the key which doesn't exist then or if it is a mandatory field, could it be that it is an identity column generated by the insert, and therefore you are not allowed to give it a value?
– Ryan Wilson
Nov 13 at 18:45
Could the problem be with your OptionSet values? You've setRecord["new_year"] = "2100"
but I'm assuming that should be "2010"? You should try to generate strong classes using the CrmSvcUtil tool
– jasonscript
Nov 14 at 1:01
Is the code in your question part of the Department.EdRecord.RecordCreate plugin?
– James Wood
Nov 14 at 11:38
add a comment |
I am trying to create a new record in Dynamics CRM using C#.
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.
I double checked to see if a school exist with the GUID by visiting the below url:
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.
c# dynamics-crm crm dynamics-crm-2015
I am trying to create a new record in Dynamics CRM using C#.
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.
I double checked to see if a school exist with the GUID by visiting the below url:
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.
c# dynamics-crm crm dynamics-crm-2015
c# dynamics-crm crm dynamics-crm-2015
edited Nov 17 at 6:11
Arun Vinoth
9,016132447
9,016132447
asked Nov 13 at 18:32
Vignesh Subramanian
3,65954197
3,65954197
1
Have you set any breakpoints to see which line is failing in your example? The provided URL, uses "new_schools", and you are using "new_school"
– Ryan Wilson
Nov 13 at 18:35
Yeah, It fails if I add the new_school. it's a mandatory field so it needs to be specified. And the new_schools is used in the upper because CRM uses plural name for rest api
– Vignesh Subramanian
Nov 13 at 18:44
I would wager that "new_school" is the key which doesn't exist then or if it is a mandatory field, could it be that it is an identity column generated by the insert, and therefore you are not allowed to give it a value?
– Ryan Wilson
Nov 13 at 18:45
Could the problem be with your OptionSet values? You've setRecord["new_year"] = "2100"
but I'm assuming that should be "2010"? You should try to generate strong classes using the CrmSvcUtil tool
– jasonscript
Nov 14 at 1:01
Is the code in your question part of the Department.EdRecord.RecordCreate plugin?
– James Wood
Nov 14 at 11:38
add a comment |
1
Have you set any breakpoints to see which line is failing in your example? The provided URL, uses "new_schools", and you are using "new_school"
– Ryan Wilson
Nov 13 at 18:35
Yeah, It fails if I add the new_school. it's a mandatory field so it needs to be specified. And the new_schools is used in the upper because CRM uses plural name for rest api
– Vignesh Subramanian
Nov 13 at 18:44
I would wager that "new_school" is the key which doesn't exist then or if it is a mandatory field, could it be that it is an identity column generated by the insert, and therefore you are not allowed to give it a value?
– Ryan Wilson
Nov 13 at 18:45
Could the problem be with your OptionSet values? You've setRecord["new_year"] = "2100"
but I'm assuming that should be "2010"? You should try to generate strong classes using the CrmSvcUtil tool
– jasonscript
Nov 14 at 1:01
Is the code in your question part of the Department.EdRecord.RecordCreate plugin?
– James Wood
Nov 14 at 11:38
1
1
Have you set any breakpoints to see which line is failing in your example? The provided URL, uses "new_schools", and you are using "new_school"
– Ryan Wilson
Nov 13 at 18:35
Have you set any breakpoints to see which line is failing in your example? The provided URL, uses "new_schools", and you are using "new_school"
– Ryan Wilson
Nov 13 at 18:35
Yeah, It fails if I add the new_school. it's a mandatory field so it needs to be specified. And the new_schools is used in the upper because CRM uses plural name for rest api
– Vignesh Subramanian
Nov 13 at 18:44
Yeah, It fails if I add the new_school. it's a mandatory field so it needs to be specified. And the new_schools is used in the upper because CRM uses plural name for rest api
– Vignesh Subramanian
Nov 13 at 18:44
I would wager that "new_school" is the key which doesn't exist then or if it is a mandatory field, could it be that it is an identity column generated by the insert, and therefore you are not allowed to give it a value?
– Ryan Wilson
Nov 13 at 18:45
I would wager that "new_school" is the key which doesn't exist then or if it is a mandatory field, could it be that it is an identity column generated by the insert, and therefore you are not allowed to give it a value?
– Ryan Wilson
Nov 13 at 18:45
Could the problem be with your OptionSet values? You've set
Record["new_year"] = "2100"
but I'm assuming that should be "2010"? You should try to generate strong classes using the CrmSvcUtil tool– jasonscript
Nov 14 at 1:01
Could the problem be with your OptionSet values? You've set
Record["new_year"] = "2100"
but I'm assuming that should be "2010"? You should try to generate strong classes using the CrmSvcUtil tool– jasonscript
Nov 14 at 1:01
Is the code in your question part of the Department.EdRecord.RecordCreate plugin?
– James Wood
Nov 14 at 11:38
Is the code in your question part of the Department.EdRecord.RecordCreate plugin?
– James Wood
Nov 14 at 11:38
add a comment |
3 Answers
3
active
oldest
votes
If new_gradelevel is an Optionset type of field, following should be the code-:
Record["new_gradelevel"] = new OptionSetValue(100000018);
Also, can you confirm the data type of new_year is String.
Hope it helps.
add a comment |
It is a common convention to name CRM lookup fields as the entity name with id
appended.
Is it possible that Record["new_school"]
should be Record["new_schoolid"]
?
OR:
Perhaps the value 100000018
does not exist in the Record["new_gradelevel"]
optionset. Maybe comment out that line and see what happens.
yeah I tried that, but then it throwed some error like new_schoolid is not found
– Vignesh Subramanian
Nov 14 at 3:11
OK, I added another possibility to the answer.
– Aron
Nov 14 at 12:20
add a comment |
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. That synchronous plugin may throw this KeyNotFoundException
error but bubble here.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287427%2fsystem-collections-generic-keynotfoundexception-dynamics-crm-c-sharp-lookup-fiel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If new_gradelevel is an Optionset type of field, following should be the code-:
Record["new_gradelevel"] = new OptionSetValue(100000018);
Also, can you confirm the data type of new_year is String.
Hope it helps.
add a comment |
If new_gradelevel is an Optionset type of field, following should be the code-:
Record["new_gradelevel"] = new OptionSetValue(100000018);
Also, can you confirm the data type of new_year is String.
Hope it helps.
add a comment |
If new_gradelevel is an Optionset type of field, following should be the code-:
Record["new_gradelevel"] = new OptionSetValue(100000018);
Also, can you confirm the data type of new_year is String.
Hope it helps.
If new_gradelevel is an Optionset type of field, following should be the code-:
Record["new_gradelevel"] = new OptionSetValue(100000018);
Also, can you confirm the data type of new_year is String.
Hope it helps.
edited Nov 17 at 5:31
Arun Vinoth
9,016132447
9,016132447
answered Nov 15 at 12:49
Aakarsh Dhawan
1196
1196
add a comment |
add a comment |
It is a common convention to name CRM lookup fields as the entity name with id
appended.
Is it possible that Record["new_school"]
should be Record["new_schoolid"]
?
OR:
Perhaps the value 100000018
does not exist in the Record["new_gradelevel"]
optionset. Maybe comment out that line and see what happens.
yeah I tried that, but then it throwed some error like new_schoolid is not found
– Vignesh Subramanian
Nov 14 at 3:11
OK, I added another possibility to the answer.
– Aron
Nov 14 at 12:20
add a comment |
It is a common convention to name CRM lookup fields as the entity name with id
appended.
Is it possible that Record["new_school"]
should be Record["new_schoolid"]
?
OR:
Perhaps the value 100000018
does not exist in the Record["new_gradelevel"]
optionset. Maybe comment out that line and see what happens.
yeah I tried that, but then it throwed some error like new_schoolid is not found
– Vignesh Subramanian
Nov 14 at 3:11
OK, I added another possibility to the answer.
– Aron
Nov 14 at 12:20
add a comment |
It is a common convention to name CRM lookup fields as the entity name with id
appended.
Is it possible that Record["new_school"]
should be Record["new_schoolid"]
?
OR:
Perhaps the value 100000018
does not exist in the Record["new_gradelevel"]
optionset. Maybe comment out that line and see what happens.
It is a common convention to name CRM lookup fields as the entity name with id
appended.
Is it possible that Record["new_school"]
should be Record["new_schoolid"]
?
OR:
Perhaps the value 100000018
does not exist in the Record["new_gradelevel"]
optionset. Maybe comment out that line and see what happens.
edited Nov 14 at 12:19
answered Nov 13 at 21:48
Aron
1,9152917
1,9152917
yeah I tried that, but then it throwed some error like new_schoolid is not found
– Vignesh Subramanian
Nov 14 at 3:11
OK, I added another possibility to the answer.
– Aron
Nov 14 at 12:20
add a comment |
yeah I tried that, but then it throwed some error like new_schoolid is not found
– Vignesh Subramanian
Nov 14 at 3:11
OK, I added another possibility to the answer.
– Aron
Nov 14 at 12:20
yeah I tried that, but then it throwed some error like new_schoolid is not found
– Vignesh Subramanian
Nov 14 at 3:11
yeah I tried that, but then it throwed some error like new_schoolid is not found
– Vignesh Subramanian
Nov 14 at 3:11
OK, I added another possibility to the answer.
– Aron
Nov 14 at 12:20
OK, I added another possibility to the answer.
– Aron
Nov 14 at 12:20
add a comment |
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. That synchronous plugin may throw this KeyNotFoundException
error but bubble here.
add a comment |
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. That synchronous plugin may throw this KeyNotFoundException
error but bubble here.
add a comment |
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. That synchronous plugin may throw this KeyNotFoundException
error but bubble here.
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. That synchronous plugin may throw this KeyNotFoundException
error but bubble here.
answered Nov 17 at 5:41
Arun Vinoth
9,016132447
9,016132447
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287427%2fsystem-collections-generic-keynotfoundexception-dynamics-crm-c-sharp-lookup-fiel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Have you set any breakpoints to see which line is failing in your example? The provided URL, uses "new_schools", and you are using "new_school"
– Ryan Wilson
Nov 13 at 18:35
Yeah, It fails if I add the new_school. it's a mandatory field so it needs to be specified. And the new_schools is used in the upper because CRM uses plural name for rest api
– Vignesh Subramanian
Nov 13 at 18:44
I would wager that "new_school" is the key which doesn't exist then or if it is a mandatory field, could it be that it is an identity column generated by the insert, and therefore you are not allowed to give it a value?
– Ryan Wilson
Nov 13 at 18:45
Could the problem be with your OptionSet values? You've set
Record["new_year"] = "2100"
but I'm assuming that should be "2010"? You should try to generate strong classes using the CrmSvcUtil tool– jasonscript
Nov 14 at 1:01
Is the code in your question part of the Department.EdRecord.RecordCreate plugin?
– James Wood
Nov 14 at 11:38