Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collection is read-only ?

Status
Not open for further replies.

tester321

Programmer
Mar 13, 2007
150
CA
Hi i'm getting the following error below and my dumb question is, how do i know what line caused the error?


Code:
Collection is read-only. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NotSupportedException: Collection is read-only.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[NotSupportedException: Collection is read-only.]
   System.Collections.Specialized.NameValueCollection.Clear() +1830662
   WebApplication1.member_area.__inWin_.securitySection1(String strPass, String strQuestion, String strAnswer) in C:\Inetpub\[URL unfurl="true"]wwwroot\WebApplication1\member-area\userControls\windowfiles\__inWin_.aspx.cs:339[/URL]
   WebApplication1.member_area.__inWin_.NewCredentials(String strPass, String strQuestion, String strAnswer) in C:\Inetpub\[URL unfurl="true"]wwwroot\WebApplication1\member-area\userControls\windowfiles\__inWin_.aspx.cs:328[/URL]
   WebApplication1.member_area.__inWin_.Page_Load(Object sender, EventArgs e) in C:\Inetpub\[URL unfurl="true"]wwwroot\WebApplication1\member-area\userControls\windowfiles\__inWin_.aspx.cs:103[/URL]
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

my guess is that its the code below, any suggestions?, thanks:


string[] items = dbstr.Split(new Char[] { '|' }, 3);
cmd.Dispose();

Session["Gender"] = items[0].Trim();
Session["PersonID"] = items[1].Trim();
Session["EMRID"] = items[2].Trim();
 
not knowing the exact order of events it happend on 1 of these 3 lines. I would guess it's the pageload event. it at least starts there.

WebApplication1.member_area.__inWin_.securitySection1(String strPass, String strQuestion, String strAnswer)
in C:\Inetpub\line 339

WebApplication1.member_area.__inWin_.NewCredentials(String strPass, String strQuestion, String strAnswer)
in C:\Inetpub\line 328

WebApplication1.member_area.__inWin_.Page_Load(Object sender, EventArgs e)
in C:\Inetpub\line 103

there doesn't seem to be anything wrong with your code. however this would prevent an out of range exception
Code:
string[] items = dbstr.Split(new Char[] { '|' }, 3);
if(items.length = 3)
{
   Session["Gender"] = items[0].Trim();
   Session["PersonID"] = items[1].Trim();
   Session["EMRID"] = items[2].Trim();
}
somewhere you are trying to add/remove/change an item in a read-only collection.
check the collection before attempting to modify
Code:
ICollection c = //get collection
if (!c.IsReadOnly)
{
   //change elements
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Ok i think i narrowed it down, any thoughts on this....
it seems to be when i call:
Code:
NewCredentials(pass, question, answer);

then:

Code:
        private void NewCredentials(string strPass, string strQuestion, string strAnswer)
        {


          using (SqlConnection connection = new SqlConnection(basic.config.Configuration.ConnectionInfo))
            { .....
 
this code would not cause a collection read-only error. the error may be within the [tt]basic.config.Configuration.ConnectionInfo[/tt] object.

to eliminate guessing at the problem set a break point in the page load event and then step through each line of code (F11). the line that fails will throw an exception.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top