Click here to Skip to main content
Click here to Skip to main content

Avoid invalid namespace error while desrializing class

, 1 Mar 2010
Rate this:
Please Sign up or sign in to vote.
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)

About the Author

r verma
Software Developer
India India
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 1 Mar 2010
Article Copyright 2010 by r verma
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid