Board index » Web Programming » Boolean Function Use in .NET

Boolean Function Use in .NET

Web Programming324
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?


-
 

Re:Boolean Function Use in .NET

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



--

Patrice



"No_Spam" <no_to_spam@comcast.net>a écrit dans le message de

Quote
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?







-

Re:Boolean Function Use in .NET

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.



"No_Spam" <no_to_spam@comcast.net>wrote in message

Quote
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?







-

Re:Boolean Function Use in .NET

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





-

Re:Boolean Function Use in .NET

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



-

Re:Boolean Function Use in .NET

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.



"No_Spam" <no_to_spam@comcast.net>wrote in message

Quote
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







-

Re:Boolean Function Use in .NET

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.



-