Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / February 2006

Tip: Looking for answers? Try searching our database.

NameValueCollections in WebMethod

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Arnold - 26 Feb 2006 23:15 GMT
Hi All,

Has anyone been able to return a
System.Collection.Specialized.NameValueCollection object from a WebMethod?

Compiles correctly, but then throws an InvalidOperationException on viewing
the asmx file...

"You must implement the Add(System.String) method on
System.Collections.Specialized.NameValueCollection because it inherits from
ICollection."

Fair enough, but ICollection does not require an Add method and neither does
IEnumerable (which ICollection extends).

Is this just a quirk of some strange serialization the CLR is attempting to
perform?

Chris
Josh Twist - 27 Feb 2006 07:58 GMT
Hi Chris,

Yes - it's because the NameValueCollection isn't XmlSerializable.

"To be XML serializable, types which inherit from ICollection must have
an implementation of Add(System.String) at all levels of their
inheritance hierarchy.
System.Collections.Specialized.NameValueCollection does not implement
Add(System.String)."

You could easily create your own custom collection by inheriting from
CollectionBase (.NET 1.x:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemcollectionscollectionbaseclasstopic.asp
)
or using generics (.NET 2.0:
http://msdn2.microsoft.com/en-us/library/ms132397(VS.80).aspx). This
should be XmlSerializable without any trouble.

Josh

Josh

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.