473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

The type namespace.classname was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

Hello,

I have a web method that serializes a class that includes among its public
fields a System.Object field to which, at runtime, I assign instances of
various different classes.
When XmlSerializer tries serializing this public field's real content I get
a "The type namespace.classname was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.". I
suppose this is due to the fact that XmlSerializer has not been informed of
what the class types of class instances that may come to be loaded in this
public field at runtime.
I think I only need to specify on the System.Object field the instance
object classes that it may come to "contain" at runtime ... unfortunately
this cannot be done with the XmlInclude attribute (which can only be applied
to methods). How can I solve this problem???

Thx.
Bob Rock

Nov 16 '05 #1
1 24739
The XmlSerializer class can only serialize types that it is aware of.

I've done this two ways:
1) Expose the property as an XmlElement and handle the serialization from
your object into XML yourself -- xs:any is the moral equivalent of
System.Object; or
2) Create an extension that intercepts the message, and manage the
serialization in the extension.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com/blogs/mickey
"Bob Rock" <no***************************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello,

I have a web method that serializes a class that includes among its public
fields a System.Object field to which, at runtime, I assign instances of
various different classes.
When XmlSerializer tries serializing this public field's real content I get a "The type namespace.classname was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.". I
suppose this is due to the fact that XmlSerializer has not been informed of what the class types of class instances that may come to be loaded in this
public field at runtime.
I think I only need to specify on the System.Object field the instance
object classes that it may come to "contain" at runtime ... unfortunately
this cannot be done with the XmlInclude attribute (which can only be applied to methods). How can I solve this problem???

Thx.
Bob Rock

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: xah | last post by:
what's the pro and con of using <script language="javascript"> vs <script type="text/javascript"> Xah xah@xahlee.org ∑ http://xahlee.org/
1
by: Opa | last post by:
Hi I'm having problem serialization an object instance which contains a public property on the object type My object hierarchy is many levels deep, so for simplicty I created to following which...
2
by: RJ | last post by:
I've been trying to find documentation that explains limitation of possible types that a webmethod can return. I realize xml serialization must take place to return the specified type. Must the...
0
by: Alex | last post by:
Hi! I have previously designed class that would read encrypted connection from registry, create a connection object (sql, oracle, oledb...) and return it to the calling class. I had to change this...
1
by: Nick Gilbert | last post by:
Hi, I'm developing a webservice that will accept an Order and forward it to a backend system, but I'm having a problem with transferring my "Order" class over a webservice. When I try and...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
2
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} ...
3
by: nick.fletcher | last post by:
Ive got a comms channel (its actually a WCF channel between a desktop amd a pocketPc) which is using standard SOAP12 over HTTP to communicate. The messages represent data transfer objects and Im...
0
by: jb489 | last post by:
Hi all, Hope I am posting this in the right forum. I seem to be having a problem when using serialization and web services. <b>Scenario:</b> I have built a web service which includes a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.