Boolean Function Use in .NET

G

Guest

I'm calling a function in .NET (ASP/VB) this way:

If Not myFunction(var1, var2) Then
....
End If

myFunction is declared as: -
Function myFunction(var1 as String, var2 as String) As Boolean
...
End Function


I'm getting an error on the 1st line of code (the IF statement), the
error reads:
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.

Stack Trace:
[NotSupportedException: Collection is read-only.]
System.Collections.Specialized.NameValueCollection.Set(String name,
String value)
System.Collections.Specialized.NameValueCollection.set_Item(String
name, String value)
ASP.login_aspx.__Render__control1(HtmlTextWriter __output, Control
parameterContainer)
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Page.ProcessRequestMain()


Any idea?
 
P

Patrice

Looks like some kind of side effect. The arguments are really just strings ?
What does the function ? From the stack trace, it looks like a control is
rendered and a collection change is attempted at some point...

Add perhaps a trace at the very beginning of the function to see if the
function is called...
 
M

Marina

You renamed the function for the purposes of posting in this newsgroup? If
so, tell us the actual name of your function and post the real code you are
using.
 
P

PL

I'm getting an error on the 1st line of code (the IF statement), the
error reads:

It is just pointing to the function call, the error is in your function and has nothing
to do with the code your posted or boolean returns from functions.

Obviously you are using somekind of collection or accessing a collection and
trying to change it, the collection however is readonly and cannot be changed.

Post the whole code if you want more help.

PL.
 
G

Guest

Function CheckCode(ByRef sMemberID As String, ByRef sGroupID As String)
As Boolean
Select Case sGroupID
Case "1"
If Len(sMemberID) = 11 Then
Return True
Else
Return False
End If
...
End Select
End Function
 
M

Marina

I don't think it is the call to this function causing the problem. It is
some other piece of code that you are not showing here related to a
collection. I think QueryString is one property that is a
NameValueCollection, might be others.
 
G

Guest

Thank you all.
I found the problem was related when I'm calling the function and not
using "toString()" for the parameters. Instead of
If Not myFunction(var1, var2) Then

I did: -
If Not myFunction(var1.toString(), var2.toString()) Then

That seems to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top