Вызовы WEB API дают ошибку 500 после обновления до sitecore 8

Недавно мы перешли на Sitecore 8.0 с Sitecore 7.5. После обновления вызовы пользовательского веб-API начали возвращать 500 кодов ошибок со следующим исключением:

Message:"An error has occurred."
ExceptionMessage:"ValueFactory attempted to access the Value property of this instance."
ExceptionType:"System.InvalidOperationException"
StackTrace:"   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping()
   at System.Web.Http.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector, HttpConfiguration configuration, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider)
   at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<>c__DisplayClass4.<MapAttributeRoutes>b__1()
   at System.Web.Http.Routing.RouteCollectionRoute.EnsureInitialized(Func`1 initializer)
   at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<MapAttributeRoutes>b__0(HttpConfiguration config)
   at System.Web.Http.CorsHttpConfigurationExtensions.<>c__DisplayClass3.<AddCorsMessageHandler>b__0(HttpConfiguration config)
   at System.Web.Http.HttpConfiguration.ApplyControllerSettings(HttpControllerSettings settings, HttpConfiguration configuration)
   at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
   at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping()
   at System.Web.Http.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector, HttpConfiguration configuration, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider)
   at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<>c__DisplayClass4.<MapAttributeRoutes>b__1()
   at System.Web.Http.Routing.RouteCollectionRoute.EnsureInitialized(Func`1 initializer)
   at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<MapAttributeRoutes>b__0(HttpConfiguration config)
   at System.Web.Http.CorsHttpConfigurationExtensions.<>c__DisplayClass3.<AddCorsMessageHandler>b__0(HttpConfiguration config)
   at System.Web.Http.HttpConfiguration.ApplyControllerSettings(HttpControllerSettings settings, HttpConfiguration configuration)
   at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
   at Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.InitializeControllerDictionary()
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Lazy`1.get_Value()
   at Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.SelectController(HttpRequestMessage request)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"

Маршруты прописаны в global.asax.cs:

protected void Application_Start(object sender, EventArgs e)
        {
            GlobalConfiguration.Configure(config =>
            {
                config.MapHttpAttributeRoutes();

                //config.Routes.MapHttpRoute(
                //    name: "DefaultApi",
                //    routeTemplate: "api/{controller}/{id}",
                //    defaults: new { id = RouteParameter.Optional }
                //);
            });
            SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
        }

person Kirtan Bhatt    schedule 16.08.2015    source источник


Ответы (1)


Это решение помогло нам, когда попытка обновления. Вы должны прочитать пост полностью, чтобы понять, что он делает, но вкратце вам нужно будет создать собственный HttpControllerSelector и заменить его на Sitecore после того, как Sitecore добавит все маршруты. Примечание. Ни одно из этих резюме изначально не принадлежит мне. Я почерпнул все это из связанной статьи.

В качестве примечания я настоятельно рекомендую избегать обновления на месте до Sitecore 8. Я бы сказал, что почти всегда лучше использовать новую установку Sitecore 8, а затем перенести свой контент через пакет. В этом блоге представлены два варианта.

person Casey    schedule 16.08.2015
comment
Было бы лучше предоставить краткое описание решения в ответе, см. Являются ли ответы, которые просто содержат ссылки в другом месте, действительно "хорошими ответами"? - person Liam; 24.08.2015
comment
Я предоставил контекст для обеих ссылок. Кроме того, я не собираюсь заниматься плагиатом или воровать чужие работы. Мы использовали именно эту статью, чтобы решить нашу проблему, и я не собираюсь копировать ее сюда. - person Casey; 24.08.2015
comment
Это сработало для меня, но мне нужно было добавить следующее: public override IDictionary<string, HttpControllerDescriptor> GetControllerMapping() { return _controllers; } к CustomHttpControllerSelector - person David Masters; 30.10.2015