I am getting an error while creating result source programmatically using Console Application.
Below is my code.
using (SPSite oSPsite = new SPSite("http://xxxx/subsite1/"))
{
Microsoft.SharePoint.SPServiceContext context = SPServiceContext.GetContext(oSPsite);
// Get the search service application proxy
SearchServiceApplicationProxy searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
SearchService searchService = SearchService.Service;
if (searchProxy != null)
{
// Get the search service application info object so we can find the Id of our Search Service App
SearchServiceApplicationInfo ssai = searchProxy.GetSearchServiceApplicationInfo();
// Get the application itself
SearchServiceApplication application = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(ssai.SearchServiceApplicationId);
FederationManager fedManager = new FederationManager(application);
SearchObjectOwner owner = new SearchObjectOwner(SearchObjectLevel.SPSite, oSPsite.RootWeb);
Source currentResultSource = fedManager.CreateSource(owner);
currentResultSource.Name = "ResultTest";
Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties QueryProperties = new Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties();
currentResultSource.CreateQueryTransform(QueryProperties, "");
currentResultSource.ProviderId = fedManager.ListProviders()["Local SharePoint Provider"].Id;
currentResultSource.Commit();
}
}
and I am getting following error.
The type 'Microsoft.Office.Server.Search.Administration.SearchServiceApplication' cannot be used as type parameter 'U' in the generic type or method 'Microsoft.SharePoint.Administration.SPPersistedObjectCollection.GetValue(System.Guid)'. There is no implicit reference conversion from 'Microsoft.Office.Server.Search.Administration.SearchServiceApplication' to 'Microsoft.SharePoint.Administration.SPPersistedObject'.
Error is showing at below line from above code.
SearchServiceApplication application = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(ssai.SearchServiceApplicationId);