We have Sandbox solution deployed to one of our Office 365/SharePoint online site collections in Sandbox solution, and we have the Visual Webpart. In Webpart, we are just querying to one of our lists and retrieving the result. We are using SPQuery, as given below:
- string strQuery = @"<Where><And><And><And><Eq><FieldRef Name='field1'/><Value Type= 'Text'>" + field1value + " </Value></Eq><Eq><FieldRef Name='field2'/><Value Type= 'Text'>" + field2value + " </Value></Eq></And><Eq><FieldRef Name='field3'/><Value Type= 'Text'>" + field3value + "</Value></Eq></And><Eq><FieldRef Name='field4'/><Value Type= 'Text'>" + field4value + "</Value></Eq></And></Where>";
-
- SPListItemCollection listItemCollection = null;
- try
- {
- SPList list = web.Lists[“listName”];
- SPQuery query = new SPQuery();
- query.Query = strQuery;
- query.RowLimit = (uint)5;
- listlistItemCollection = list.GetItems(query);
- }
- catch (Exception ex)
- {
- string error = ex.Message + ex.StackTrace;
- LogError(error);//This is our custom method to log the errors
- }
Issue / Exception
While executing the code given above, we were getting an exception as follows:
One or more field types are not installed properly. Go to the list settings page to delete these fields.
Server stack trace
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
at Microsoft.SharePoint.SPListItemCollection.get_Count()
at Microsoft.SharePoint.SPListItemCollection_SubsetProxy.Count__get()
at Microsoft.SharePoint.SPListItemCollection_SubsetProxy.get_Count()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.SharePoint.SPListItemCollection_SubsetProxy.get_Count()
at Microsoft.SharePoint.SPListItemCollection.Count__get()
at Microsoft.SharePoint.SPListItemCollection.get_Count()
Solution
We Googled a little bit and the same exception is for various causes.
In our case, one of the fields, ' field4', which we are using for our query, is not available in the content type, which is associated with the list. Thus, we added the respective field in the content type and the query worked.
Lesson Learned
To avoid such kinds of errors, we need to make sure that all the fields used in the queries or in ViewFields property must be available in the content type, which is associated to the list.