Filed under: Proxies

NameValueCollection and Proxies

Today i learnt yet another painful lesson at work. When you generate a service proxy using SvcUtil, the NameValueCollection data type does not get parsed. In my case it parsed it into a ArrayOfXElement object type by creating  a System.Collections.Specialized namespace within the proxy. I Googled around, then asked around, thinking that i missed some basic object type in c# (read ArrayOfXElement). But that was thankfully not the case. I found a lot of workaround for the given issue. Many involved writing a simple parser (as a wrapper, don't get worried). But a simpler and wiser approach was not to use a NameValueCollection in the first place. Use a Dictionary instead. The same issue comes up in the event of a ArrayList it seems. Use a List object for that. After a little bit of googling i found that the NameValueCollection and the Arraylist are Week Types. According to this discussion thread: http://stackoverflow.com/questions/939118/wcf-serialization-problem-using-namevaluecollection Week types and Weekly typed are two different things. How and why are questions which i am still trying to resolve. But the big and small is this: Do not use NameValueCollections, its an unnecessary headache.