locked
Azure WebSite IoC - No parameterless constructor defined for this object RRS feed

  • Question

  • User-1423807876 posted

    I've published my application in Azure Web Site, but the dependency injection is not working, but in my local machine everything works perfectly. My application is using MVC 5.2.2 and Autofac 3.5.0.2, both for .Net 4.5.1. The exception message is: "No parameterless constructor defined for this object." And says to make sure that the controller has a parameterless public constructor How can i fix that?

    Thanks

    Friday, November 7, 2014 7:16 AM

Answers

  • User-1423807876 posted

    I´ve found where was the problem. When publishing the MVC application, Visual Studio didnt upload all necessary files.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 10, 2014 8:30 AM

All replies

  • User281315223 posted

    Without knowing exactly what class or object you are trying to use it might be difficult to determine exactly what you would need to do to fix it. However if this is occurring for a particular controller, based on the error message, you would need to ensure that for that Controller (and any other classes that you are using this on) that you have a parameterless constructor like the following example demonstrates :

    public class ExampleController : Controller
    {
          // Example logger to demonstrate the use of a parameterized constructor
    
          // Controller that accepts a parameter (populated through DI)
          public ExampleController(ILogger logger)
          {
               _logger = logger;
          }
    
          // Example of a parameterless constructor (you need one of these)
          public ExampleController()
          {
    
          }
    }

    So just ensure that whatever class you are using this for that you have an actual empty "parameterless" constructor being used.

    Saturday, November 8, 2014 2:44 PM
  • User-1423807876 posted

    My application is based on that project on GitHub: https://github.com/imranbaloch/ASPNETIdentityWithOnion

    In that project, it has a bootstrapper to inject the dependencies on the MVC application. On local machine works perfectly but in Azure doesn't. If you would like, is a very simple sample demo to test it and maybe could help me.

    Thanks Rion

    Sunday, November 9, 2014 8:47 PM
  • User-1423807876 posted

    I´ve found where was the problem. When publishing the MVC application, Visual Studio didnt upload all necessary files.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 10, 2014 8:30 AM