Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Avoid invalid namespace error while desrializing class

0.00/5 (No votes)
1 Mar 2010 1  
Following trick will also provide a way how to handle/pass objects to web service through a web application as in web applications developer will not be able to update proxy class (old trick followed in case of class library). When you try to serialize your class let say using Binary...
Following trick will also provide a way how to handle/pass objects to web service through a web application as in web applications developer will not be able to update proxy class (old trick followed in case of class library).

When you try to serialize your class let say using Binary Formatter, it will also include its parent namespace in hexa decimal format. Now suppose you want to send this byte array (stream content of object) over a network to any web service or external code then depending upon its physical location one may encountered some error like "namespace not found" or "namespace not valid".

For avoiding this kind of error a trick is to maintain a separate class library/central class which will have two static methods one for serializing object type parameter and second method to deserialize byte[] type parameter. Also in case if you want to save this content to database then better use a temporary class for serialization with minimal/only required properties. Populate this class with your initial class and then serialize it.

This implementation will ensure that whatever is your parent namespace your serialized class will be accessible in all locations wherever this temporary class/class library is referenced.

I have tested this approach by passing a class object to a web service. Only thing was that class to be passed was referenced in both web application and web service.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here