ActivationException

Topics: Security Application Block
Nov 11, 2010 at 6:43 AM

I am getting the following error with my IAuthorizationProvider:

Activation error occured while trying to get instance of type IAuthorizationProvider, key "DefaultRules"

This link was a similar issue about Logging App Block:

http://stackoverflow.com/questions/2900403/activation-error-occured-while-trying-to-get-instance-of-type-logwriter

Here they said it might have something to do with it being a class library. Is that the problem. It said to use a FileConfigurationSource, but I can't see how to use that for the AuthorizationFactory. Can someone please help me with an example?

This is my code:

private IAuthorizationProvider rules = AuthorizationFactory.GetAuthorizationProvider("DefaultRules");

and my security config section:

<securityConfiguration defaultAuthorizationInstance="DefaultRules">
    <authorizationProviders>
      <add type="Microsoft.Practices.EnterpriseLibrary.Security.AuthorizationRuleProvider, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="DefaultRules">
        <rules>
          <add expression="R:Administrators AND NOT I:?" name="EditRule" />
        </rules>
      </add>
    </authorizationProviders>
  </securityConfiguration> 

Thanks

Nov 11, 2010 at 6:51 AM

If you don't have the option to put your securityConfiguration section in your executable project's configuration file, then you can make use of the AuthorizationProviderFactory class:

IConfigurationSource configSource = new FileConfigurationSource(@"pathToConfig.config");
AuthorizationProviderFactory factory = new AuthorizationProviderFactory(configSource);

IAuthorizationProvider authProvider = factory.Create("DefaultRules");

 

Sarah Urmeneta
Global Technologies & Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 11, 2010 at 7:09 AM

Thanks, Sarah!  :-)