Click here to Skip to main content
15,891,184 members
Articles / Web Development / ASP.NET
Tip/Trick

Avoid invalid namespace error while desrializing class

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
1 Mar 2010CPOL1 min read 7.6K   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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --