0
votes

I have a WCF application where it is listening for a message. The EventHandler uses the ServiceClient which uses HttpClient to call another API.

The IoC class:

public static class IoC
{
    public static IContainer Initialize()
    {
        ObjectFactory.Initialize(x =>
        {
            // Handlers
            x.For<IHandle>().Use<EventHandler>();

            // Service Clients
            x.For<HttpClient>().Use<HttpClient>();
            x.For<IServiceClient>().Use<ServiceClient>();
        });

        return ObjectFactory.Container;
    }
}

I tried adding this after the Initialize but before the return:

ObjectFactory.Configure(x =>
{
    x.Scan(scan =>
    {
        scan.LookForRegistries();
        scan.Assembly("System.Net.Http");
    });
});

But, I still get the exception in the title.

1
maybe you already loaded that assembly? erictummers.com/2014/05/01/… - Hogan
I don't think so. I added the ObjectFactory.Configure after I got the exception to try and fix it. - ScubaSteve
You are not getting an exception!!! See following : restfulapi.net/http-status-202-accepted - jdweng
It is an exception. It's a StructureMap Exception Code 202, not an http status code. - ScubaSteve

1 Answers

0
votes

I was able to resolve this issue. The problem was that I was using an older version of StructureMap (v2.6.4.1) which was not compatible with System.Net.Http, Version=4.2.0.0. After updating to the latest version and making some adjustments since ObjectFactory doesn't exist in the latest version, I was getting an error:

No default Instance is registered and cannot be automatically determined for type 'System.Net.Http.HttpMessageHandler'

This is because StructureMap defaultly tries to use the greediest constructor. To fix this, I changed my DI for HttpClient to this:

x.For<HttpClient>().Use<HttpClient>().SelectConstructor(() => new HttpClient());