A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Tuesday, January 15, 2008

InfoPath Error: The given key was not present in the dictionary.

If this error occurs when you try to submit the form, then there can be two reasons for this. The data connection name is not correct or the URL used in the data connection is not correct. Sometimes, it is hard to pin point the problem because the URL will not be accepted if it has a problem, no matter how minor. An extra space, an illegal character, etc are the problems that are hard to locate and are the source of this error. This usually occurs when you try to submit the form programmatically because directly publishing the form to the SharePoint allows you to select the site and library so there is no chance of entering a malformed URL but when you submit the form programmatically using a data connection, you have to provide the URL manually. The details of the error are as follows:
------------------
 The given key was not present in the dictionary Source: Microsoft.Office.InfoPath.Server Stack trace:   at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.ExecuteOMCallWithExceptions(OMCall d, ExceptionFilter exceptionFilter)
   at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMSecurityContext.ExecuteOMCall(Solution solution, SecurityLevel methodSecurityLevel, ExceptionFilter exceptionFilter, OMCall d)
   at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMSecurityContext.ExecuteOMCall(Solution solution, SecurityLevel methodSecurityLevel, OMCall d)
   at Microsoft.Office.InfoPath.Server.DocumentLifetime.DataConnectionCollectionHost.get_Item(String name)
   at function() in Pathcode.cs:line 394
   at function() in Pathcode.cs:line 290Location:Void ExecuteOMCallWithExceptions(Microsoft.Office.InfoPath.Server.DocumentLifetime.OMCall, Microsoft.Office.InfoPath.Server.DocumentLifetime.ExceptionFilter)
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
---------------------------
Code to submit form programmatically:
 public void FormEvents_Loading(object sender, LoadingEventArgs e)
 {
       string srcLoc = e.InputParameters["Source"].ToString();
       srcLoc = srcLoc.Substring(0, srcLoc.IndexOf("/", 8));
       libLoc = srcLoc + e.InputParameters["XmlLocation"].ToString();
 }
FileSubmitConnection SubmitConnection = (FileSubmitConnection)this.DataConnections["Mainsubmit"];
SubmitConnection.FolderUrl = libLoc.Substring(0, libLoc.LastIndexOf("/"));
SubmitConnection.Execute();
"Mainsubmit" is the data connection name. If there is a spelling mistake in this name, you will get the error. If there is a spelling mistake in the URL used in this connection, again there will be an error. You need to be extra careful when publishing the form. It is hard to notice the problem because the form publishes OK with out any problems and you only get the error when you run the form from SharePoint.