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

2

7

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
Aggression answered 30/10, 2014 at 12:21 Comment(6)
where is the registration for IHostBufferPolicySelector?Maines
what is IHostBufferPoslicySelector and what is the avaialble (default) implementation?Aggression
Please post the complete stack trace.Brandabrandais
@MaYaN: That's not the complete stack trace. Please include all inner exceptions as well. And especially everything down here. So we need to see the complete stack trace from the beginning of the request up to this point.Brandabrandais
@Steven, that was indeed the complete Stack, I have now updated the question to include all the other bits but that's all of it.Aggression
@MaYaN: If you call .ToString() on that exception, you'll get all the relevant information from that exception that we need to help you.Brandabrandais
A
1

It turned out that the exception only bubbles up when I have the Common Language Runtime Exceptions checked to thrown

When I untick the checkbox everything behaves as normal! which is weird! also wrapping it in a Try-Catch (Exception) doesn't even catch it which makes it even more interesting/werid!

Aggression answered 30/10, 2014 at 12:53 Comment(5)
Great you found out how to get a complete stack trace. Can you update your question with this information?Brandabrandais
Here's an example of how a complete stack trace might look like.Brandabrandais
Steven, what I posted in the question is all I am getting, a break point is never hit even when I wrap it in a Try-Catch so can't do a ToString() on it. What I posted above was what I coppied directly from the Thrown dialog box in VisualStudio. It is not even captured in a Global App Domain Exception HandlerAggression
I'm sorry, but without more information about what code is triggering this exception it is impossible for anyone to help you.Brandabrandais
@Brandabrandais - Bumped into this a little too late, i think the stack trace becomes available if we run the Diagnostics tool in Visual studio and capture the Call Stack by selecting Historical debugging from this exception event.Supraorbital
K
4

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.

Kliber answered 10/10, 2015 at 22:11 Comment(0)
A
1

It turned out that the exception only bubbles up when I have the Common Language Runtime Exceptions checked to thrown

When I untick the checkbox everything behaves as normal! which is weird! also wrapping it in a Try-Catch (Exception) doesn't even catch it which makes it even more interesting/werid!

Aggression answered 30/10, 2014 at 12:53 Comment(5)
Great you found out how to get a complete stack trace. Can you update your question with this information?Brandabrandais
Here's an example of how a complete stack trace might look like.Brandabrandais
Steven, what I posted in the question is all I am getting, a break point is never hit even when I wrap it in a Try-Catch so can't do a ToString() on it. What I posted above was what I coppied directly from the Thrown dialog box in VisualStudio. It is not even captured in a Global App Domain Exception HandlerAggression
I'm sorry, but without more information about what code is triggering this exception it is impossible for anyone to help you.Brandabrandais
@Brandabrandais - Bumped into this a little too late, i think the stack trace becomes available if we run the Diagnostics tool in Visual studio and capture the Call Stack by selecting Historical debugging from this exception event.Supraorbital

© 2022 - 2024 — McMap. All rights reserved.