In my last SharePoint application I’ve created I had an issue with the SPQuery object. I ran into the following error when running my code:
"One or more field types are not installed properly. Go to the list settings page to delete these field"
Strange because all the fields where working in that list I was querying. The code I was using was:
Private Function GetNumberOfNotifications() As Integer
Dim number As Integer = 0
Dim list As SPList
Dim q As New SPQuery
list = SPContext.Current.Web.Lists.TryGetList("VerlofAanvraag")
If Not list Is Nothing Then
q.Query = …
number = number + list.GetItems(q).Count
End If
list = SPContext.Current.Web.Lists.TryGetList("VerlofAanvraagItems")
If Not list Is Nothing Then
q.Query = …
number = number + list.GetItems(q).Count
End If
list = SPContext.Current.Web.Lists.TryGetList("OverurenKalender")
If Not list Is Nothing Then
q.Query = …
number = number + list.GetItems(q).Count
End If
Return number
End Function
The problem was that I was reusing the SPQuery object without reinitializing it. Adding q=new SPQuery() before setting the new query caml code solved the problem.