IndexOutOfRangeException
Old forum URL: forums.lhotka.net/forums/t/5478.aspx
mase posted on Friday, September 26, 2008
I'm using CSLA 2.1 and have been having these error intermittently since the launch of the web application. I'm not able to reproduce it or track it down and need help!
I posted about it here a while back: http://forums.lhotka.net/forums/post/23987.aspx
I have a pretty standard and basic Business Object library. I do not utilize Authorization Rules and sometimes add Validation Rules. It doesn't appear to be consistent either. It happens on any/all business objects and always seems to stem from the CanReadProperty()
Index was outside the bounds of the array.
Exception type 'System.IndexOutOfRangeException' was caught.
Source: mscorlib
Target Site: Void Insert(TKey, TValue, Boolean)
Stack Trace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Csla.Security.SharedAuthorizationRules.GetManager(Type objectType, Boolean create) in C:\www\myApp\v6\CSLA\Security\SharedAuthorizationRules.cs:line 36
at Csla.Security.AuthorizationRules.get_TypeRules() in C:\www\myApp\v6\CSLA\Security\AuthorizationRules.cs:line 50
at Csla.Security.AuthorizationRules.HasReadAllowedRoles(String propertyName) in C:\www\myApp\v6\CSLA\Security\AuthorizationRules.cs:line 226
at Csla.ReadOnlyBase`1.CanReadProperty(String propertyName) in C:\www\myApp\v6\CSLA\ReadOnlyBase.cs:line 258
at Csla.ReadOnlyBase`1.CanReadProperty(Boolean throwOnFalse) in C:\www\myApp\v6\CSLA\ReadOnlyBase.cs:line 187
Index was outside the bounds of the array.
Request.URL.PathAndQuery: /artists/Articles.aspx?artistID=2625
Exception type 'System.IndexOutOfRangeException' was caught.
Source: mscorlib
Target Site: Void Insert(TKey, TValue, Boolean)
Stack Trace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Csla.Security.SharedAuthorizationRules.GetManager(Type objectType, Boolean create) in C:\www\myApp\v6\CSLA\Security\SharedAuthorizationRules.cs:line 36
at Csla.Security.AuthorizationRules.get_TypeRules() in C:\www\myApp\v6\CSLA\Security\AuthorizationRules.cs:line 50
at Csla.Security.AuthorizationRules.HasReadAllowedRoles(String propertyName) in C:\www\myApp\v6\CSLA\Security\AuthorizationRules.cs:line 226
at Csla.ReadOnlyBase`1.CanReadProperty(String propertyName) in C:\www\myApp\v6\CSLA\ReadOnlyBase.cs:line 258
at Csla.ReadOnlyBase`1.CanReadProperty(Boolean throwOnFalse) in C:\www\myApp\v6\CSLA\ReadOnlyBase.cs:line 187
at myApp.BusinessObjects.UserSession.get_Username() in C:\www\myApp\v6\BusinessObjects\Objects\UserSession.cs:line 67
at myApp.UI.Master_controls_Nav.SetLoginTab()
at myApp.UI.Master_controls_Nav.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at Artists_Articles.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at myApp.UI.BasePage.OnLoad(EventArgs e)
at myApp.UI.ArtistBasePage.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Index was outside the bounds of the array.
Request.URL.PathAndQuery: /Shows/Shows.aspx?VenueID=10313
Exception type 'System.IndexOutOfRangeException' was caught.
Source: mscorlib
Target Site: Void Insert(TKey, TValue, Boolean)
Stack Trace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Csla.Security.SharedAuthorizationRules.GetManager(Type objectType, Boolean create) in C:\www\myApp\v6\CSLA\Security\SharedAuthorizationRules.cs:line 36
at Csla.Security.AuthorizationRules.get_TypeRules() in C:\www\myApp\v6\CSLA\Security\AuthorizationRules.cs:line 50
at Csla.Security.AuthorizationRules.HasReadAllowedRoles(String propertyName) in C:\www\myApp\v6\CSLA\Security\AuthorizationRules.cs:line 226
at Csla.Core.BusinessBase.CanReadProperty(String propertyName) in C:\www\myApp\v6\CSLA\Core\BusinessBase.cs:line 448
at Csla.Core.BusinessBase.CanReadProperty(Boolean throwOnFalse) in C:\www\myApp\v6\CSLA\Core\BusinessBase.cs:line 376
at myApp.BusinessObjects.Venue.get_State() in C:\www\myApp\v6\BusinessObjects\Objects\Venue.cs:line 174
at Shows_Shows2.SetTitles()
at Shows_Shows2.DisplayShows()
at Shows_Shows2.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
JoeFallon1 replied on Friday, September 26, 2008
I do not utilize Authorization Rules
It happens on any/all business objects and always seems to stem from the CanReadProperty
==============================================================
Since you are not using Authorization rules, just remove the CanReadProperty code from your Properties. Then see if the problem goes away.
Joe
mase replied on Friday, September 26, 2008
I will give that a shot and see if it works.
I had the CanReadProperty() and CanWriteProperty() because I imagined introducing Authorization rules eventually.
Can you refresh my memory as to what Authorization rules would be used for? What is the situation and benefit for using them? Is it essentially for permissions and roles on the business level?
mase replied on Friday, September 26, 2008
Also, I can't figure out why it happens sometimes but not consistently. Why would having this code (CanReadProperty(true)) work ok 90% of the time and then produce an exception the rest of the time? Espeically if I have not setup Authorization rules, I would expect it should behave the same way each time.
Thanks for the help
ajj3085 replied on Monday, September 29, 2008
Don't use the overloads of CanXXXProperty that don't take the property name. They have been depreciated in future versions, and have been the source of many problems. You may be hitting the debug vs. release compilation issues.
mase replied on Monday, September 29, 2008
Ok, great. This is exactly what I have been wondering about. Good to know. Removing them and hopefully will see these errors disappear.
ajj3085 replied on Monday, September 29, 2008
Well, if you want to use auth rules you should still call CanXXXProperty... just don't call the ones that omit the propertyName parameter.
sergeyb replied on Monday, September 29, 2008
I think (pretty sure) those signatures of CanXXXProperty now
generate “deprecated” warnings during compile time. So, you
should be able to easily find all the instances when you are using old signatures
that does not take property name as parameter.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: ajj3085
[mailto:cslanet@lhotka.net]
Sent: Monday, September 29, 2008 3:34 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] IndexOutOfRangeException
Well, if you want to use auth rules you should still call
CanXXXProperty... just don't call the ones that omit the propertyName
parameter. ">
Copyright (c) Marimer LLC