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
MaYaN
  • 6,683
  • 12
  • 57
  • 109
  • where is the registration for `IHostBufferPolicySelector`? – qujck Oct 30 '14 at 12:24
  • what is `IHostBufferPoslicySelector` and what is the avaialble (default) implementation? – MaYaN Oct 30 '14 at 12:25
  • Please post the complete stack trace. – Steven Oct 30 '14 at 12:28
  • @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. – Steven Oct 30 '14 at 12:34
  • @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. – MaYaN Oct 30 '14 at 12:37
  • @MaYaN: If you call `.ToString()` on that exception, you'll get all the relevant information from that exception that we need to help you. – Steven Oct 30 '14 at 12:42

2 Answers2

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.

Steven
  • 166,672
  • 24
  • 332
  • 435
rubStackOverflow
  • 5,615
  • 2
  • 29
  • 43
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!

MaYaN
  • 6,683
  • 12
  • 57
  • 109
  • Great you found out how to get a complete stack trace. Can you update your question with this information? – Steven Oct 30 '14 at 12:57
  • [Here's an example](https://stackoverflow.com/questions/25973238/simpleinjector-no-parameterless-constructor-defined-for-this-object) of how a complete stack trace might look like. – Steven Oct 30 '14 at 13:00
  • 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 Handler` – MaYaN Oct 30 '14 at 13:31
  • I'm sorry, but without more information about what code is triggering this exception it is impossible for anyone to help you. – Steven Oct 30 '14 at 13:37
  • @Steven - 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. – MuKa May 16 '18 at 16:43