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 6175443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:55:32+00:00 2026-05-23T23:55:32+00:00

In one of my classes I have an internal constructor which is being used

  • 0

In one of my classes I have an internal constructor which is being used for unit testing, and a private constructor that my application calls. The internal has parameters for my dependencies while the private constructor has no parameters and makes a call to BuildUp to use setter injection. As-is the code crashes on me with the following error:

StructureMap Exception Code:  245
Error while trying to create an InstanceBuilder for My.Namespace.And.Class, My.Assembly, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null
at StructureMap.Graph.PluginCache.<.cctor>b__1(Type t) in c:\code\structuremap\Source\StructureMap\Graph\PluginCache.cs:line 40
at StructureMap.Util.Cache`2.get_Item(KEY key) in c:\code\structuremap\Source\StructureMap\Util\Cache.cs:line 82
at StructureMap.Graph.PluginCache.FindBuilder(Type pluggedType) in c:\code\structuremap\Source\StructureMap\Graph\PluginCache.cs:line 52
at StructureMap.Container.BuildUp(Object target) in c:\code\structuremap\Source\StructureMap\Container.cs:line 243
at StructureMap.ObjectFactory.BuildUp(Object target) in c:\code\structuremap\Source\StructureMap\ObjectFactory.cs:line 297

Object reference not set to an instance of an object.
at StructureMap.Construction.ConstructorFunctionBuilder`1.CreateBuilder(Plugin plugin) in c:\code\structuremap\Source\StructureMap\Construction\ConstructorFunctionBuilder.cs:line 25
at StructureMap.Construction.BuilderCompiler.FuncCompiler`1.CreateBuilder(Plugin plugin) in c:\code\structuremap\Source\StructureMap\Construction\BuilderCompiler.cs:line 51
at StructureMap.Construction.BuilderCompiler.CreateBuilder(Plugin plugin) in c:\code\structuremap\Source\StructureMap\Construction\BuilderCompiler.cs:line 12
at StructureMap.Graph.PluginCache.<.cctor>b__1(Type t) in c:\code\structuremap\Source\StructureMap\Graph\PluginCache.cs:line 36

If I change the default constructor so it’s public instead of private, or even internal, then everything works as expected. Is this the intended behavior with private and internal constructors or is this a bug?

  • 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-23T23:55:33+00:00Added an answer on May 23, 2026 at 11:55 pm

    Yes, you need a public constructor for structuremap to auto-configure the instance.

    IMHO if you’re making explicit calls to the container (BuildUp) then you’re adding coupling to the DI, which defeats some of the purpose of DI (to remove coupling). I much prefer to stick to simple constructor injection, then If I DO for some reason need to fill dependencies explicitly, just call ask the container for the concrete class (ObjectFactory.GetInstance<Class>()), and it will auto-fill the dependencies in the most complex public constructor.

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

Sidebar

Related Questions

I have two classes one of which inherits from the other. Im trying to
I have some classes that, for one reason or another, cannot be or need
In one of my projects, I have some classes that represent entities that cannot
I have a number of classes that represents business transaction calls: executing appropriate stored
I have several classes that are derived from SPPersistedObject. One of them is my
So I have a class called User . It has an internal constructor. I
I am using Hibernate to do mapping. One of my classes have a set
I have 2 classes where I have one to send commands to a socket,
I have a field for addedBy in one of my classes. I've set up
I have a Visual Studio C++ solution with 3 projects: one contains all classes

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.