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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:18:08+00:00 2026-06-13T08:18:08+00:00

I have an object: public class TestEvent : IEvent { private string _id; public

  • 0

I have an object:

public class TestEvent : IEvent
{
    private string _id;

    public TestEvent()
    {
    }

    public TestEvent(string eventId)
    {
        _id = eventId;
    }
}

And I have a StructureMap registry:

public class TheRegistry : Registry
{
    public TheRegistry()
    {
        Scan(_ =>
            {
                _.TheCallingAssembly();
                _.AddAllTypesOf<IEvent>().NameBy(t => t.Name.ToUpper());
            });
    }
}

I’m trying to get a named instance of IEvent using the StructureMap container and passing in a constructor argument for “eventId”:

var id = "TESTEVENT";
var args = new ExplicitArguments();
args.SetArg("eventId", id);
var eventInstance = _container.GetInstance<IEvent>(args, id);

I think the docs suggest it should work, however I’m getting an ArgumentNullException:

{“Trying to find an Instance of type MyProject.IEvent, MyProject,
Version=1.0.0.0, Culture=neutral, publicKeyToken=null\r\nParameter name: instance”}

All the code works properly if I remove the second constructor, and just grab the named instance.

UPDATE:

Following Kirk’s investigation, I’ve been able to workaround this “issue” by creating a simple object to hold any required arguments. It works now.

public class EventArguments
{
    public string EventId { get; set; }
}

...

var eventName = Context.Parameters.EventTypeName.ToString().ToUpper();
var args = new ExplicitArguments();
args.SetArg("args", new EventArguments { EventId = eventName });
var eventInstance = _container.GetInstance<IEvent>(args, eventName);
  • 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-06-13T08:18:09+00:00Added an answer on June 13, 2026 at 8:18 am

    Full disclosure: I’ve never used StructureMap before, so I could be misunderstanding how it’s intended to be used. But as near as I can tell, either this use-case is intentionally not supported by StructureMap, or it’s a bug.

    But first, you have one error; you need to fix your id to match your .ToUpper call (i.e. it should be var id = "TESTEVENT";, not var id = "TestEvent";).

    Once you’ve done that, though, it still doesn’t work. Inspecting the source code, it’s clear why. The constructor of the types are inspected (in this case, TestEvent) and if any constructor declares a parameter whose type is “simple” (i.e. primitives, strings, etc.) then that constructor is categorically disqualified from participating in the .GetInstance behavior.

    Specifically, if you examine StructureMap.Graph.PluginFamily.discoverImplicitInstances():

    private void discoverImplicitInstances()
    {
        _pluggedTypes.Each((key, plugin) =>
        {
            if (!plugin.CanBeAutoFilled) return;
    
            if (hasInstanceWithPluggedType(plugin)) return;
    
            ConfiguredInstance instance = new ConfiguredInstance(plugin.PluggedType).WithName(key);
            FillInstance(instance);
        });
    }
    

    It’s that first line in the lambda that is the culprit:

    if (!plugin.CanBeAutoFilled) return;
    

    That’s the line that is disqualifying your constructor (and thus your type). Strings can’t be “auto-filled” since you can’t just new one up, and they wouldn’t be registered for injection.

    If you comment that line out your code will now work. What puzzles me is that while I understand why your constructor couldn’t be implicitly created, the code as written seems to also disqualify code from working when you are passing explicit arguments as you’ve done.

    Maybe someone with more experience with StructureMap will be able to offer more expert guidance, but hopefully this was better than nothing.

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

Sidebar

Related Questions

I have a command object: public class Job { private String jobType; private String
I have the following object: public class QueueItem { public long _id { get;
I have a custom object ExportType : public class ExportType{ protected String name; protected
Suppose I have the following service object public class UserService { @Autowired private UserDao
I have a following object: public class TestObject { public String Something { get;
I have the following object: public class Client { [BsonId] public string Name {
So I have this object: public class JournalItem { public string Description { get;
I have the following Object: public class Constraint { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) int id; String
I have an object - @Entity public class myObject{ public string fieldA; public string
I have a object: public class Ticket { public string EventName {get;set;} public string

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.