2015-08-16 101 views
3

最近,我們從Sitecore 7.5升級到Sitecore 8.0。升級後,自定義Web API調用開始返回與下面的異常500個錯誤代碼:升級到sitecore後WEB API調用出現500錯誤8

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")); 
     } 

回答

3

This solution嘗試升級時爲我們工作。您應該完整閱讀該文章以瞭解其功能,但總之您需要創建一個自定義的HttpControllerSelector,並在Sitecore添加完所有路由之後將其與Sitecore交換。注意:這個摘要都不是我的。我從鏈接的文章中收集了所有這些內容。

就像旁註一樣,我強烈建議避免將Sitecore 8升級到原位。我會說,使用全新安裝的Sitecore 8然後通過軟件包遷移您的內容幾乎總是一個更好的選擇。 This blog是一個很好的看看這兩個選項。

+0

最好在答案中提供解決方案的摘要,請參閱[是否只包含其他鏈接的答案,真的是「好答案」?](http://meta.stackexchange.com/questions/8231/ are-answers-that-just-contain-links-elsewhere-really-good-answers) – Liam

+0

我向兩個鏈接提供了上下文。另外,我不會剽竊或竊取別人的工作。我們用這篇確切的文章來解決我們的問題,我不打算把它粘貼在這裏。 – Casey

+2

這工作對我來說,但我需要添加以下內容:'公共覆蓋IDictionary <字符串,HttpControllerDescriptor> GetControllerMapping() { return _controllers; }'到'CustomHttpControllerSelector' –