AuthorizationFactory Design Time Exception

Topics: Security Application Block
Sep 20, 2007 at 7:05 AM
Hello,

If I include a call to AuthorizationFactory.GetAuthorizationProvider() in the constructor of a custom control, VS displays an error when I try to use that control on a WinForm. Adding the control to the form programatically works, in other words the code compiles and runs successfully, but the form generates a similar exception when opened in design mode. Any ideas?

---------------------------
Microsoft Visual Studio
---------------------------
Failed to create component 'CustomButton'. The error message follows:

'System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Practices.EnterpriseLibrary.Security.Configuration.AuthorizationProviderDataRetriever.MapName(String name, IConfigurationSource configSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Object...'
Sep 20, 2007 at 12:09 PM
Hi,

You don't need authorization at design time, so you should attempt to build it if Component.DesignMode is false. This means you will have to move the creation of the authorization provider away from the constructor, as the value for the DesignMode property is only available after the control has been sited.

Fernando


marcelgr wrote:
Hello,

If I include a call to AuthorizationFactory.GetAuthorizationProvider() in the constructor of a custom control, VS displays an error when I try to use that control on a WinForm. Adding the control to the form programatically works, in other words the code compiles and runs successfully, but the form generates a similar exception when opened in design mode. Any ideas?

---------------------------
Microsoft Visual Studio
---------------------------
Failed to create component 'CustomButton'. The error message follows:

'System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Practices.EnterpriseLibrary.Security.Configuration.AuthorizationProviderDataRetriever.MapName(String name, IConfigurationSource configSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Object...'


Sep 20, 2007 at 12:24 PM
Learning something new every day!

Thanks, it works like a charm.
Sep 20, 2007 at 12:31 PM
Excellent!

Regards,
Fernando


marcelgr wrote:
Learning something new every day!

Thanks, it works like a charm.

Feb 18, 2009 at 7:15 AM
Hi,  I have some problem related system.web.security, enterpriselibrary and sql server. here's the error:

 Exception information:
    Exception type: InvalidCastException
    Exception message: Unable to cast object of type 'System.Int32' to type 'System.String'.

Stack trace:    at System.Data.SqlClient.SqlBuffer.get_String()
   at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
   at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)
   at System.Web.Security.RolePrincipal.IsInRole(String role)
   at Microsoft.Practices.EnterpriseLibrary.Security.WordExpression.Evaluate(IPrincipal principal)
   at Microsoft.Practices.EnterpriseLibrary.Security.RoleExpression.Evaluate(IPrincipal principal)
   at Microsoft.Practices.EnterpriseLibrary.Security.AuthorizationRuleProvider.Authorize(IPrincipal principal, String ruleName)
   at PageBase.IsUserAuthorizedForRule(String ruleName)
   at General_TugasDanPengerjaan.Page_Load(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.

Please, i need your help..

thanks
Feb 18, 2009 at 7:42 AM
Edited Feb 18, 2009 at 7:47 AM
Could you include more details?  At what point do you get this exception? What are you exactly trying to do?  Your code snippet would be helpful.


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