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

  • SEARCH
  • Home
  • 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 656677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:44:25+00:00 2026-05-13T22:44:25+00:00

I am using Autofac 2.1.12 to handle my dependency injection, and am having trouble

  • 0

I am using Autofac 2.1.12 to handle my dependency injection, and am having trouble with one specific issue. I can’t seem to resolve a NameValueCollection dependency.

Consider the following code snippet:

class Foo
{
    public Foo(NameValueCollection collection) { }
}

static class Run
{
    public static void Main()
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<NameValueCollection>();
        builder.RegisterType<Foo>();

        using (var scope = builder.Build())
            scope.Resolve<Foo>();
    }
}

It will crash with an unhandled DependencyResolutionException:

Circular component dependency
detected: Foo ->
System.Collections.Specialized.NameValueCollection
-> System.Collections.Specialized.NameValueCollection.

However, if I replace NameValueCollection with any other type, the code works fine.

Am I doing something wroing, is there something special about the NameValueCollection type that I am missing, or is this an issue with Autofac itself?

  • 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-13T22:44:25+00:00Added an answer on May 13, 2026 at 10:44 pm

    This is by design. See Autowiring:

    Autofac automatically chooses the constructor with the most parameters that are able to be obtained from the container.

    Try registering NameValueCollection like so (not sure if this will work, though):

    builder.RegisterType<NameValueCollection>().UsingConstructor();
    

    If that doesn’t work, try

    builder.Register(c => new NameValueCollection());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Autofac to handle dependency injection in my application. However, I have one
I am using Autofac to handle dependency injection in my application. In order not
I am using ASP.NET MVC 3 and Autofac for my dependency injection. I am
I'm using Autofac and want to resolve the correct implementation of the current assembly
I'm using Autofac. I want to inject a different implementation of a dependency based
I have run into an issue while creating a data service and using Autofac
I have started to use Autofac following this tutorials: http://flexamusements.blogspot.com/2010/09/dependency-injection-part-3-making-our.html Simple class with no
I can see how I can instantiate objects of classes using autofac, and then
Using Autofac in ASP.NET along with the ContainerDisposalModule, how can i support fire and
I'm trying to get up and going with Autofac, but am having trouble figuring

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.