Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6842591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:07:09+00:00 2026-05-27T00:07:09+00:00

i am trying to imitate the sample given with using autofac, but constantly getting

  • 0

i am trying to imitate the sample given with using autofac, but constantly getting no parameterless constructor missing error for my contoller. what am i doing wrong should i create a modelbinder for the irepository?

here is how the bootstrapper looks like. mocked testers put in here it s just as in example does not really reflect the actual intention. there gonna a seperate test project.

Mock<iproductrepository> mock = new Mock<iproductrepository>();
mock.Setup(m => m.products).Returns(new List<product>()
                                        {
                                            new product() {name = "football", price = 25},
                                            new product() {name = "surf board",price = 179},
                                            new product() {name = "running shoes", price = 95}
                                        }.AsQueryable()

    );

builder.RegisterInstance(mock.Object).As<iproductrepository>();
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterControllers(Assembly.GetExecutingAssembly());


var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

and here is controller simple

public class productcontroller : Controller
{
    private readonly iproductrepository _productrepository;


    /// <summary>
    /// 
    /// </summary>
    /// <param name="productrepository"></param>
    public productcontroller(iproductrepository productrepository)
    {
        _productrepository = productrepository;
    }

    //
    // GET: /product.controller/

    public ViewResult list()
    {
        return View(_productrepository.products);
    }

}

getting this error

No parameterless constructor defined for this object. Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code. Exception Details:
System.MissingMethodException: No parameterless constructor defined
for this object. Source Error: An unhandled exception was generated
during the execution of the current web request. Information regarding
the origin and location of the exception can be identified using the
exception stack trace below. Stack Trace: [MissingMethodException: No
parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,
Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean
fillCache) +241 System.Activator.CreateInstance(Type type, Boolean
nonPublic) +69
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext
requestContext, Type controllerType) +67 [InvalidOperationException:
An error occurred when trying to create a controller of type
‘*.productcontroller’. Make sure that the controller has

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:07:09+00:00Added an answer on May 27, 2026 at 12:07 am

    Autofac in the method builder.RegisterControllers registers the controllers which name end with “Controller” with a capital C :

    ...
    if (typeof (IController).IsAssignableFrom(t))
       return t.Name.EndsWith("Controller");
    else
       return false;
    ...
    

    So you need to rename your controller to productController (anyway in C# ProductController according to the naming convenctions) or register the your controllers by “hand” in the container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Trying to connect to a SQL Server 2005 instance remotely but getting the following
I am using a custom overlay on my MapView and I'm trying to imitate
Trying to create an array of structs (new to C), but I am getting
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I am trying to imitate this tutorial about creating a simple Apple-themed breadcrumb found
I'm trying to program two buttons to imitate the up/down arrow key behavior, meaning
Trying to create an SSIS package to process a Datacube. Using SMS 2008, I've
Trying to deploy application using ClickOnce to a webserver running sharepoint. I can publish
I have been trying to post login credentials to an https site using cURL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.