The type SimpleInjector.Integration.Web.Mvc.SimpleInjectorDependencyResolver does not appear to implement Microsoft.Practices.ServiceLocation.IServiceLocator.

Coordinator
Mar 6, 2015 at 8:57 PM
This question was originally posted here by user leonibr, but was moved to this thread to prevent the original thread from cluttering.


Hi, I followed your steps and end up with this. I don´t know what is going on here:
Public Shared Function Initialize(app As IAppBuilder) As Container
    Dim container = GetInitializeContainer(app)

    container.Verify()

    ' FOLLOWING LINE THROWS THE EXCEPTION BELLOW
    DependencyResolver.SetResolver(New SimpleInjectorDependencyResolver(container))  

    Return container
End Function
An exception of type 'System.ArgumentException' occurred in System.Web.Mvc.dll but was not handled in user code

Additional information: The type SimpleInjector.Integration.Web.Mvc.SimpleInjectorDependencyResolver does not appear to implement Microsoft.Practices.ServiceLocation.IServiceLocator.
Coordinator
Mar 6, 2015 at 8:58 PM
Seems to me that the method overload resolution of your compiler (VB) picked the SetResolver overload that takes in an Object instead of the IDependencyResolver. I get the same exception when I do the following:
DependencyResolver.SetResolver(DirectCast(New SimpleInjectorDependencyResolver(container), Object))
But this works without problems:
DependencyResolver.SetResolver(New SimpleInjectorDependencyResolver(container))
Try doing something like this:
Dim resolver As IDependencyResolver = New SimpleInjectorDependencyResolver(container)
DependencyResolver.SetResolver(resolver)
The complete test project code I used, looks like this:
Imports System.Web.Optimization
Imports SimpleInjector
Imports System.Reflection
Imports SimpleInjector.Integration.Web.Mvc

Public Class MvcApplication
    Inherits System.Web.HttpApplication

    Sub Application_Start()

        Dim container = New Container()

        container.RegisterMvcControllers(Assembly.GetExecutingAssembly())

        container.Verify()

        DependencyResolver.SetResolver(New SimpleInjectorDependencyResolver(container))

        AreaRegistration.RegisterAllAreas()
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters)
        RouteConfig.RegisterRoutes(RouteTable.Routes)
        BundleConfig.RegisterBundles(BundleTable.Bundles)

    End Sub
End Class
Coordinator
Mar 6, 2015 at 9:00 PM
[Sep 15, 2014 at 6:44 PM by leonibr]

TheBigRic, dot_NET_Junkie,
This did the magic:
Dim resolver As IDependencyResolver = New SimpleInjectorDependencyResolver(container)
DependencyResolver.SetResolver(resolver)
Thank you!!