Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this ActivationException when using Simple Injector with WebApi Self Hosted in OWIN?

I have a very simple Web Api v2.2 self hosted in OWIN

public class StartUp
{
    public void Configuration(IAppBuilder appBuilder, IConfigReader configReader)
    {
        var container = new Container();

        container.Register<IConfigReader, ConfigReader>();

        var config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        appBuilder.UseWebApi(config);
    }
}

When I then use on my Main() as:

WebApp.Start(baseAddress, appBuilder => 
                new StartUp().Configuration(appBuilder, new ConfigReader()));

However when I try to execute the last line appBuilder.UseWebApi(config); I get the following exception:

A first chance exception of type 'SimpleInjector.ActivationException' occurred in SimpleInjector.dll

Additional information: The given type IHostBufferPolicySelector is not a concrete type. Please use one of the other overloads to register this type.

Complete Stack:

SimpleInjector.ActivationException occurred _HResult=-2146233088
_message=The given type IHostBufferPolicySelector is not a concrete type. Please use one of the other overloads to register this type.
HResult=-2146233088 IsTransient=false Message=The given type IHostBufferPolicySelector is not a concrete type. Please use one of the other overloads to register this type. Source=SimpleInjector
StackTrace: at SimpleInjector.Advanced.DefaultConstructorResolutionBehavior.VerifyTypeIsConcrete(Type implementationType) InnerException:

The problem is not that single interface it looks like SimpleInjector is trying to find a binding for Every Single Interface; If I provide a dummy implementation for IHostBufferPolicySelector it throws for some other interface e.g. IExceptionHandler etc.

There is a related thread HERE but I am not sure how it relates to SimpleInjector? The Self host is a Console App which has the following packages installed:

  • Simple Injector ASP.NET Web API Integration v2.61
  • Simple Injector Execution Context Scoping v2.61
  • Simple Injector v2.61
  • OWIN v1.0
  • Microsoft.Owin v2.0.2
  • Microsoft.Owin.Hosting v2.0.2
  • Microsoft ASP.NET Web API 2.2 OWIN v5.2.2
  • Microsoft ASP.NET Web API 2.2 OWIN Self Host v5.2.2
like image 977
MaYaN Avatar asked Oct 30 '14 12:10

MaYaN


1 Answers

According to Simple Injector:

The exceptions you are showing are 'first chance exceptions'. These exceptions are thrown by Simple Injector but they are caught and processed by Simple Injector and they won't bubble up the call stack. It is possible that you see them in some debugger output window, but they are quite normal and nothing to worry about.

like image 119
rubStackOverflow Avatar answered Sep 17 '22 12:09

rubStackOverflow