1

Considering this code :

public class A
{
    public B b { get; set; }
}

public class B : IInitializable
{
    #region IInitializable Members

    public void Initialize()
    {
        throw new NotImplementedException();
    }

    #endregion
}

class Program
{
    static void Main(string[] args)
    {
        WindsorContainer container = new WindsorContainer();
        container.Register(Component.For<A>());
        container.Register(Component.For<B>());

        try
        {
            A a = container.Resolve<A>();
            // goes here and a.b is null !!!
        }
        catch (Exception ex)
        {
            // never goes here :(
            Console.WriteLine(ex);
        }
    }
}

I would have expected the NotImplementedException to be propagated to the main catch. Instead, the exception is caught by windsor and the property a.b is null...

Any idea to get my exception correctly propagated ?

1 Answers1

0

This is by design. You're resolving A which has B as an optional dependency. Windsor can't resolve B because of the exception, so it treats it as non-resolvable, and since it's an optional dependency, there is no error, it just carries on without injecting B.

Here's a very similar situation, along with a workaround.

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275