Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Dingley 1470 posts 3427 karma points c-trib
    Jun 16, 2015 @ 15:20
    Simon Dingley
    0

    v6 > v7 Upgrade - No UmbracoContext with PhoenixConvertors

    I am trying to upgrade an inherited solution from v6 to v7, so far so good but I need to upgrade some legacy MNTP data and was attempting to use Phoenix Convertors but have run into the following exception:

    {"Message":"An error has occurred.","ExceptionMessage":"Value cannot be null.\r\nParameter name: umbracoContext","ExceptionType":"System.ArgumentNullException","StackTrace":" at Umbraco.Web.WebApi.UmbracoApiController..ctor(UmbracoContext umbracoContext)\r\n at Umbraco.Web.WebApi.UmbracoAuthorizedApiController..ctor()\r\n at PhoenixConverters.Controllers.PhoenixApiController..ctor()\r\n at lambda_method(Closure )\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"}

    The solution uses the AutoFac IoC framework and the following initializes the IoC container as per the docs:

            // Register umbraco context, mvc controllers and api controllers
            _builder.Register(c => UmbracoContext.Current).AsSelf();
            _builder.RegisterControllers(Assembly.GetExecutingAssembly());
            _builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
            _builder.RegisterApiControllers(typeof(PhoenixTreeController).Assembly);
    

    I can see that UmbracoContext is null (if I am correct) but not sure why or how to rectify. The rest of the back office appears to work fine and the initial tree loads I just get the exception when selecting one of the PhoenixConvertors child nodes in the developer section.

    Any ideas welcomed.

    Thanks, Simon

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Jun 17, 2015 @ 13:12
    Simon Dingley
    0

    Still struggling with this but have a little progress thanks to an old thread I found here:

    Web API UmbracoApiController does not use DependencyResolver

    Which led me to include:

            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
    

    But I now get the following exception but not sure where it's being thrown:

    Failed to retrieve target datatypes from API
    
    A delegate registered to create instances of 'Umbraco.Web.UmbracoContext' returned null.
    
    EXCEPTION DETAILS:
    
    Autofac.Core.DependencyResolutionException: A delegate registered to create instances of 'Umbraco.Web.UmbracoContext' returned null.
    STACKTRACE:
    
    at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
       at Autofac.Core.Resolving.InstanceLookup.Execute()
       at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Activators.Reflection.AutowiringParameter.<>c__DisplayClass2.<CanSupplyValue>b__0()
       at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
       at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
       at Autofac.Core.Resolving.InstanceLookup.Execute()
       at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
       at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)
       at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
       at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType)
       at Autofac.Integration.WebApi.AutofacWebApiDependencyScope.GetService(Type serviceType)
       at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)
       at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
    
Please Sign in or register to post replies

Write your reply to:

Draft