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
    Feb 01, 2017 @ 12:59
    Simon Dingley
    0

    UmbracoAuthorizedApiController - Make sure that the controller has a parameterless public constructor

    I am working on an upgrade and have forked the handy work of Kevin Giszewski on the PhoenixConverters project.

    I've updated the package dependencies to use the latest Umbraco v7.5.8 but when attempting to access the plugin an exception is thrown saying

    An error occurred when trying to create a controller of type 'PhoenixApiController'. Make sure that the controller has a parameterless public constructor..

    The controller is pretty simple really and just inherits from UmbracoAuthorizedApiController. Even when adding a parameterless constructor the exception remains.

    Am I missing something? It's not any different to other UmbracoAuthorizedApiController instances I've created in the past as far as I can tell.

  • John Bergman 483 posts 1132 karma points
    Feb 02, 2017 @ 05:01
    John Bergman
    0

    What is the full stack trace? (look in the log).

    It could be that the constructor in PhoenixApiController is throwing an exception... this would give you the same (albeit incorrect) error as if there is no constructor.

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Feb 02, 2017 @ 09:31
    Simon Dingley
    0

    Hi John,

    This is the odd thing because the exception does not appear in the log files. I get it in the browser only but you are correct there is an inner exception thrown:

    {
       "Message":"An error has occurred.",
       "ExceptionMessage":"An error occurred when trying to create a controller of type 'PhoenixApiController'. Make sure that the controller has a parameterless public constructor.",
       "ExceptionType":"System.InvalidOperationException",
       "StackTrace":"   at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n   at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()",
       "InnerException":{
          "Message":"An error has occurred.",
          "ExceptionMessage":"Value cannot be null.\r\nParameter name: umbracoContext",
          "ExceptionType":"System.ArgumentNullException",
          "StackTrace":"   at Umbraco.Web.WebApi.UmbracoApiControllerBase..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)"
       }
    }
    

    I've even tried adding the following constructors but the issue remains:

    public class PhoenixApiController : UmbracoAuthorizedApiController
    {
        public PhoenixApiController() : base(UmbracoContext.Current)
        {
    
        }
    
        public PhoenixApiController(UmbracoContext umbracoContext) : base(umbracoContext)
        {
    
        }
    
        [...]
    }
    
  • Erik Foppen 20 posts 62 karma points
    Jan 24, 2018 @ 12:38
    Erik Foppen
    0

    Hi Simon,

    I'm having the same issue here. Have you ever managed to get this working?

    cheers

    Erik

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Jan 24, 2018 @ 13:53
    Simon Dingley
    0

    Seems sooo looong ago now I can't remember exactly but I have just opened up my fork and the PhoenixApiController I have inherits from UmbracoAuthorizedJsonController - see if that helps and let me know?

    Edit: Additionally, I have no constructors in the class

Please Sign in or register to post replies

Write your reply to:

Draft