0
votes

I am new to Sitecore,SoleNet. I have installed and configured Solr to work with Sitecore and I am able to see results. I am now using code.

I added the connection string to UnityMVCActivator.cs in the Start() Startup.Init("http://localhost:8983/solr/sitecore_web_index");

In my controller - Actionresults Index() var solr = ServiceLocator.Current.GetInstance>();

I get this error

[InvalidOperationException: The type ISolrOperations1 does not have an accessible constructor.] Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForNullExistingObject(IBuilderContext context) +226 lambda_method(Closure , IBuilderContext ) +39 Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.b__0(IBuilderContext context) +33 Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +337 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +396 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides) +238

[ResolutionFailedException: Resolution of the dependency failed, type = "SolrNet.ISolrOperations`1[Niddk.Model.SearchResultsViewModel]", name = "(none)". Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type ISolrOperations`1 does not have an accessible constructor.

At the time of the exception, the container was:

Resolving SolrNet.ISolrOperations1[Niddk.Model.SearchResultsViewModel],(none) ] Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides) +500 Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +20 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +55

[ActivationException: Activation error occured while trying to get instance of type ISolrOperations1, key ""] Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +156 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance() +62 Niddk.Web.Controllers.SearchController.Index() in C:\Users\ksivanandan\Source\Repos\web\Niddk\Niddk.Web\Controllers\SearchController.cs:23 lambda_method(Closure , ControllerBase , Object[] ) +87 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +229 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +35 System.Web.Mvc.<>c__DisplayClass15.b__12() +80 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +453 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +453 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +533

My ViewModel

public class SearchResultsViewModel
{

    [SolrField("headline_t")]
    public string Headline { get; set; }


}

Any help is greatly appreciated.

Thank you!

1

1 Answers

0
votes

Edit: this thread was also raised in GitHub in SolrNet and the project maintainer provided the right answer.

The problem is that for registering he is using the built in IoC but then resolving via Unity.

Original response I may be reading your code wrong or something might be missing from the post but you are not passing the type:

In my controller - Actionresults Index()

var solr = ServiceLocator.Current.GetInstance<[you are missing this part]>();

When using generics you need to specify the type. I thinks this part would not even compile because of the .GetInstance>() being incomplete.