removing from collection in session variable

  • Thread starter Thread starter Alexandre Soares
  • Start date Start date
A

Alexandre Soares

Hi,

On some pages, I put a collection in the session, which uses the InProc
mode. On pages where the session is extensively used (many collections are
put into it), whenever I try to remove an item from a collection using the
RemoveAt method, I get a "Index was out of range. Must be non-negative and
less than the size of the collection. Parameter name: index" error even
tough I verify in debug that the collection count is equal to 1 and I try to
RemoveAt(collection.count - 1) (so the index is non-negative and is less
than the size of the collection). And that error occurs if I try to remove
any index from the collection. On the other hand, on one specific page where
I put only one collection in the session (but exactly the same logic and
code apply), eveything works fine. Can someone help me out?

Thank you very much!
 
Alexandre Soares said:
Hi,

On some pages, I put a collection in the session, which uses the InProc
mode. On pages where the session is extensively used (many collections are
put into it), whenever I try to remove an item from a collection using the
RemoveAt method, I get a "Index was out of range. Must be non-negative and
less than the size of the collection. Parameter name: index" error even
tough I verify in debug that the collection count is equal to 1 and I try to
RemoveAt(collection.count - 1) (so the index is non-negative and is less
than the size of the collection). And that error occurs if I try to remove
any index from the collection. On the other hand, on one specific page where
I put only one collection in the session (but exactly the same logic and
code apply), eveything works fine. Can someone help me out?

Just for fun, try using Remove(collection[0]);
 
Hi,

On some pages, I put a collection in the session, which uses the InProc
mode. On pages where the session is extensively used (many collections
are
put into it), whenever I try to remove an item from a collection using
the
RemoveAt method, I get a "Index was out of range. Must be non-negative
and
less than the size of the collection. Parameter name: index" error even
tough I verify in debug that the collection count is equal to 1 and I
try to
RemoveAt(collection.count - 1) (so the index is non-negative and is less
than the size of the collection). And that error occurs if I try to
remove
any index from the collection. On the other hand, on one specific page
where
I put only one collection in the session (but exactly the same logic and
code apply), eveything works fine. Can someone help me out?

Thank you very much!

try pulling the collection out into a local var, remove the item, then
reassign the session var. i think i've seem problems like this when i
don't explictly reassign it....

but worth a try, and IMHO is actually a little cleaner approach (but i'm a
purist!)
 
That's actually what I am doing (pulling out the collection into a local
variable, removing the item and puting it back into the session :)
 
That's actually what I am doing (pulling out the collection into a local
variable, removing the item and puting it back into the session :)

"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> a écrit dans le
message
de news:o[email protected]...
try pulling the collection out into a local var, remove the item, then
reassign the session var. i think i've seem problems like this when i
don't explictly reassign it....

but worth a try, and IMHO is actually a little cleaner approach (but
i'm a
purist!)

ah, wasn't sure...I have seen people act directly on the Session object,
which I'm not saying that's incorrect (dunno for sure)....
 
Back
Top