Friday, 15 July 2016

Office 365 / SharePoint Online – sandbox solution – error : One or more field types are not installed properly. Go to the list settings page to delete these fields.

Hi All,

Today new issue and solution :)

In this article I'll explain the issue / exception / error which we faced while getting the data from the list in sandbox solution and the solution to the issue.

Background: We have SandBox solution deploying to one of the our Office 365/SharePoint online site collection. In sandbox solution we have visual WebPart. In WebPart we are just querying to one of the our list and fetch the result. We are using SPQuery like as follows

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;
  listItemCollection = 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 above code 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 little bit and same exception is for different – different causes.

But in our case, one of the field ' field4' which we are using query, is not available in the content type which is associated to the list. So we added the respective field in content type and query worked.

Lesson Learned : To avoid such kind of errors we need to make sure that all the fields used in queries or in ViewFields property must be available in the content type which is associated to the list.

Thanks!

Enjoy Reading :)

As usual any comment / suggestion / feedback / questions always welcome :)