Custom Software Apps & SharePoint Consulting

As a SharePoint consultant, I get the chance to work through a lot of interesting problems. In this case, programmatically accessing BCS External Lists in SharePoint is a bit like working in a parallel universe.  Most list access rules will continue to apply, however there are some very special caveats that one must remember.

For the reader’s findability convenience, I am organizing this guide in terms of the errors that the user will most likely encounter.

SharePoint limitationsReading and querying an External List

“The given key was not present in the dictionary”

This error may appear if any one of the CAML query conditions have not been met:

–    Viewfields were not specified

–     Viewfields and Query were specified via the ViewFields property (as opposed to using the ViewXML and Query properties)

–          The Method name was not included.  In most cases this should be either ‘Read List’ or ‘ReadList’.

Here is an example of a correctly laid out CAML query for BCS:

SPQuery query = new SPQuery();
query.ViewXml = @”
<Method Name=’Read List’/>
<FieldRef Name=’SUBMISSION_ID’/>
<Value Type=’Text’>FilterValHere</Value>
<FieldRef Name=’SUBMISSION_ID’/>
<FieldRef Name=’PACKAGE_ID’/>

“The Finder ‘ReadList’ cannot be found in ViewGroup associated with SpecificFinder (Read Item) operation ‘ReadItem’ in EntityNamespace”

This sort of error can appear if an incorrect Method name was supplied above.  Pay attention to caps and spaces.  In my own case, I had to pull open SharePoint Designer and check the exact name of the Read List operation, and I found that there was a space in the method name.

The shim execution failed unexpectedly – Proxy creation failed. Default context not found.

This error will appear if you did not declare the SPServiceContextScope.  You can perform this operation as shown below.  Note that the scope must be declared BEFORE the SPWeb is instantiated:

using (SPSite site = new SPSite(“http://mysite”))
   var context = SPServiceContext.GetContext(site);
using (var scope = new SPServiceContextScope(context))
      using (SPWeb web = site.RootWeb)
         SPList myList = _web.Lists[“myList”];
SPQuery query = new SPQuery();

For the complete guide to BCS External Lists in SharePoint, download the PDF. Or check out our blog on SharePoint 2013 Task App Lists

Carol Donnelly
Director of Consulting @ Entrance
Carol has close to a decade of experience leveraging software technologies to create enterprise content management, bi & analytics, collaboration, and need-specific software solutions that help businesses transform into a modern digital enterprise. She has helped clients address challenges related to contract and records management, contract and AFE approval workflow, lease digitization, and offshore extranets.
Carol Entrance Software Consulting making software better