Could not load type 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ITypeRegistrationsProvider

前端 未结 1 697
滥情空心
滥情空心 2021-01-25 10:09

I recently tried to implement authentication using asp.net identity with 4.6.1 framework. After installing all the required packages I am getting the following error when runnin

1条回答
  •  走了就别回头了
    2021-01-25 10:37

    TL;DR

    Configure the OWIN startup class in your web.config / app.config appSettings like this:

         
    

    The whole story

    The problem has to do with the way that OWIN looks for the Startup class. For some strange reason, it finds ITypeRegistrationsProvider and tries to load it.

    OWIN has three ways to look for the application startup class:

    • Naming Convention: Katana looks for a class named Startup in namespace matching the assembly name or the global namespace.
    • OwinStartup Attribute: This is the approach most developers will take to specify the startup class. The following attribute will set the startup class to the TestStartup class in the StartupDemo namespace.
    • The appSetting element in the Configuration file

    If you look carefully the call stack, you'll see that the problem is related to the second one, looking for the attribute: Owin.Loader.DefaultLoader.SearchForStartupAttribute. For some reason it finds ITypeRegistrationsProvider is suitable as an Startup class, and tries to instance it. Apart from being incorrect, it fails because you cannot instance an interface.

    Once you know what the problem is, if you read OWIN source code, in particular OwinBuilder.GetAppStartup, you'll see that the first option to find the startup class is to use the one specified in appSettings:

    string appStartup = ConfigurationManager.AppSettings[Constants.OwinAppStartup];
    

    If you specify yous startup class in web.config you'll prevent the application from looking and trying to instance the wrong class. So, to solve the problem, you simply have to specify the app startup class in your web.config or app.config appSettings, like this:

      
             
    
    

    Notes:

    • in the linked document you'll see owin:appStartup, but if you check the source code you'll see that the right syntax is owin:AppStartup (OwinAppStartup constant, as used in the code snippet above)
    • you can specify yous startup class in servera ways, but I recommend you to specify it like this "namespace.ClassName, assemblyName" which is the safest one.

    If your configuration is right, I warranty that the Owin loader will take your real startup class, and the error will not happen.

    0 讨论(0)
提交回复
热议问题