473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

removing from collection in session variable

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!
Nov 18 '05 #1
4 1457
"Alexandre Soares" <so*********@hotmail.com> wrote in message
news:eM**************@TK2MSFTNGP09.phx.gbl...
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]);
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
On Mon, 12 Jul 2004 15:58:12 -0400, Alexandre Soares
<so*********@hotmail.com> wrote:
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!)

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #3
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:op**************@web-1161d.webservices.nrt...
On Mon, 12 Jul 2004 15:58:12 -0400, Alexandre Soares
<so*********@hotmail.com> wrote:
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!)

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #4
On Tue, 13 Jul 2004 08:30:28 -0400, Alexandre Soares
<so*********@hotmail.com> wrote:
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:op**************@web-1161d.webservices.nrt...
On Mon, 12 Jul 2004 15:58:12 -0400, Alexandre Soares
<so*********@hotmail.com> wrote:
> 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!)

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET



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)....

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mvr | last post by:
Hi all IIS 5.0, ASP, and https:// I have "DataEntrypage.asp" which is a data entry page(about 250 data elements includes text boxes, radio buttons, check boxes, drop down boxes etc). ...
2
by: Gus Gustafson | last post by:
I set ndi in a repost of a page: window.location.href= '../Test/test.aspx' + '?ndi=' + theform.domain_SELECT.options.selectedIndex; In the test.aspx.cs code-behind, I test if ndi is set as ...
0
by: Hazzard | last post by:
I am trying to figure out how to add an additional value to a querystring collection so that when I click on a datagrid cell, there will be a key to distinguish it from another column's...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
5
by: vsr | last post by:
is there any way to remove some information from trace, tracing by default displays session , application variables, but i need to remove these two from trace.can any let me know how can i do it?
6
by: Joe | last post by:
Hello All: I have a webform (WebForm1.aspx) that retrieves a value from a database (_formSessionId) the first time that it is posted. After the user filles in the form, he/she clicks a Button...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
8
by: Michael Schwarz | last post by:
Hi, I have a problem where I have two requests (i.e. two different windows that are using the same session) that are accessing the session collection. The requests will need more time on the...
9
by: dotnetismylife | last post by:
Hi all, I have a question, in the following code: using System; using System.Diagnostics; namespace ConsoleApplication1 { class TestClass {
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.