|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Serializing Custom Generic Collection (Of InterfaceType)from NameObjectCollectionBase and implements IXmlSerializable. We have an interface class IBaseCondition and several classes that implement IBaseCondition (StringCondition, NumericCondition, etc.). We have another class (SearchCriteria) that has a property (Conditions) which is defined as Public ReadOnly Property Conditions() As NameObjectCollection(Of IBaseCondition). When we use return this SearchCriteria class from a web service, we get an exception stating "System.NotSupportedException: Cannot serialize interface IBaseCondition.". Is there any way I can get this to work? We must be able to serialize the IBaseCondition since the NameObjectCollection is a collection of IBaseCondition. Thanks, Mythran
Show quote
Hide quote
"Mythran" wrote: Then you need to make IBaseCondition inherit IXmlSerializable.> We have written a generic class NameObjectCollection(Of T) that inherits > from NameObjectCollectionBase and implements IXmlSerializable. We have an > interface class IBaseCondition and several classes that implement > IBaseCondition (StringCondition, NumericCondition, etc.). We have another > class (SearchCriteria) that has a property (Conditions) which is defined as > Public ReadOnly Property Conditions() As NameObjectCollection(Of > IBaseCondition). > > When we use return this SearchCriteria class from a web service, we get an > exception stating "System.NotSupportedException: Cannot serialize interface > IBaseCondition.". > > Is there any way I can get this to work? We must be able to serialize the > IBaseCondition since the NameObjectCollection is a collection of > IBaseCondition. > > Thanks, > > Mythran > Mike
Show quote
Hide quote
"Family Tree Mike" <FamilyTreeM***@discussions.microsoft.com> wrote in I ended up implementing IXmlSerializable in NameObjectCollection(Of T) and message news:6EB9D9E8-66CE-4F11-BC37-592BCADE9069@microsoft.com... > > > "Mythran" wrote: > >> We have written a generic class NameObjectCollection(Of T) that inherits >> from NameObjectCollectionBase and implements IXmlSerializable. We have >> an >> interface class IBaseCondition and several classes that implement >> IBaseCondition (StringCondition, NumericCondition, etc.). We have >> another >> class (SearchCriteria) that has a property (Conditions) which is defined >> as >> Public ReadOnly Property Conditions() As NameObjectCollection(Of >> IBaseCondition). >> >> When we use return this SearchCriteria class from a web service, we get >> an >> exception stating "System.NotSupportedException: Cannot serialize >> interface >> IBaseCondition.". >> >> Is there any way I can get this to work? We must be able to serialize >> the >> IBaseCondition since the NameObjectCollection is a collection of >> IBaseCondition. >> >> Thanks, >> >> Mythran >> > > Then you need to make IBaseCondition inherit IXmlSerializable. > > Mike SearchCriteria. We have numerous classes that implement IBaseCondition and it would be a headache to add new ones and update the existing ones just for serialization. So far, it looks like the everything is serialized/deserialized correctly (I have printed the serialized object as a string and it looks correct, then took the string and deserialized and the values of the objects come out correct too). Thanks, Mythran Hi Mythran,
>> We have numerous classes that implement IBaseCondition and Since the XmlSerializer requires a concrete class to instantiate when >> it would be a headache to add new ones and update the existing ones >> just for serialization. deserializing, there is not much options with the current design (a collection of an interface type). You may consider based on current implementation, let the classes that implements the IBaseCondition to do the actual work generating XML during serialization and instances during deserialization, and in the NameObjectCollection's IXmlSerializable implementation, call those individual classes' method to return the XML or instances. Best regards. Jie Wang Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msd***@microsoft.com. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications. Note: MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 2 business days is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ""Jie Wang [MSFT]"" <jie***@online.microsoft.com> wrote in message
Show quoteHide quote news:BTQ0o1w#JHA.2552@TK2MSFTNGHUB02.phx.gbl... Thanks for your response,> Hi Mythran, > >>> We have numerous classes that implement IBaseCondition and >>> it would be a headache to add new ones and update the existing ones >>> just for serialization. > > Since the XmlSerializer requires a concrete class to instantiate when > deserializing, there is not much options with the current design (a > collection of an interface type). > > You may consider based on current implementation, let the classes that > implements the IBaseCondition to do the actual work generating XML during > serialization and instances during deserialization, and in the > NameObjectCollection's IXmlSerializable implementation, call those > individual classes' method to return the XML or instances. > > Best regards. > > Jie Wang > What I ended up doing was implementing IXmlSerializer on the collection class itself. During serialization, I loop through and serialize each item in the collection, creating an XmlSerializer for each iteration based on the type of the object stored in the collection. So far, this works great. Thanks, Mythran
vb.net and Ms SQL Connection ?
Using "Me" Using WPF with a "normal" windows app Unable to connect to the remote server How to reference class properties using MyClass("PropertyName") VB Net/Com Interoperability/Late Binding [XPost] - Visual Studio 2008 - Instruct IDE Not To Generate Adapter Client Server app using winsock setting a timeout for web service response Session Variables in asp.net |
|||||||||||||||||||||||