StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

前端 未结 8 1201
-上瘾入骨i
-上瘾入骨i 2020-12-20 11:05

I am new to StructureMap. I have downloaded and am using version 2.6.1.0. I keep getting the below error:

StructureMap Exception Code: 202 No Def

相关标签:
8条回答
  • 2020-12-20 11:34

    Where's your bootstrapping for the IConfiguration concrete class?

    I.e:

    x.For<IConfiguration>().Use<Configuration>();
    
    0 讨论(0)
  • 2020-12-20 11:39

    I was getting the same error message, but for a different reason. I had a class Foo that defined two constructors like so:

    public class Foo : IFoo
    {
        private Bar _bar;
    
        public Foo()
        {
           _bar = new Bar();
        }
    
        public Foo(Bar bar)
        {
            _bar = bar;
        }
    }
    

    and my StructureMap configuration was like so:

    For<IFoo>.Use<Foo>();
    

    I kept getting an error message like

    202 No Default Instance defined for Bar

    The problem was that StructureMap was trying to construct a Foo using the constructor that takes a parameter, instead of using the parameterless default constructor. I solved it using the answer in How to define a default constructor by code using StructureMap? like so:

    For<IFoo>.Use(() => new Foo());
    
    0 讨论(0)
  • 2020-12-20 11:41

    I was seeing the same error. In my case, I had a typo in the implementation name, so the interface and implementation names did not match.

    public class FooTypo : IFoo
    

    Where I should have had:

    public class Foo : IFoo
    
    0 讨论(0)
  • 2020-12-20 11:42

    I also had this issue when I was using Visual Studio 2015 with NCrunch. All you have to do is toggle an option to true in the configuration menu item under NCrunch. Switching initialize to configure didn't work for me.

    The option is under Build Settings, it is named 'Copy referenced assemblies to workspace'

    0 讨论(0)
  • 2020-12-20 11:46

    When I got this error it was because I forgot to mark my class public. That simple.

    0 讨论(0)
  • 2020-12-20 11:48

    Mine was because I had accidentally referenced the concrete type in the constructor of another class rather than the interface

    eg in structuremap i had

    x.For<IFoo>().Use<Foo>();
    x.For<IBar>().Use<Bar>();
    

    and constructor for Foo looked like this

    public class Foo : IFoo {
        public Foo(Bar bar) {...}
    }
    

    when it should have looked like this as SM couldn't just create an instance of Bar, it only knows how to make an IBar:

    public class Foo : IFoo {
        public Foo(IBar bar) {...}
    }
    

    It also meant that my exception referenced the concrete type instead of the interface but I missed that initially

    0 讨论(0)
提交回复
热议问题