A Practical Guide to SharePoint 2013

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

Monday, September 3, 2007

Fix "calling GetScopeID from a non-Office server binary" error

Scopes are usually used in search code. One of the very common errors when working with scopes in search code is as following:
"Calling GetScopeID from a non-Office server binary."
This error occurs when you instantiate the query object, for example: 
KeywordQuery kwQuery = new KeywordQuery(site);
To resolve this issue, include the correct namespace when defining the kwQuery object, for example:
Microsoft.Office.Server.Search.Query.KeywordQuery kwQuery = new Microsoft.Office.Server.Search.Query.KeywordQuery(site)
When you skip the namespace, SharePoint tries to call the GetScopeID() from an assembly different than the one it should be using. This especially happens when both of the following namespaces are included in your code:
using Microsoft.SharePoint.Search.Query;
using Microsoft.Office.Server;