473,804 Members | 3,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The type namespace.class name 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.class name 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 24768
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******** ********@TK2MSF TNGP10.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.class name 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
2607
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
2642
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 produces the same error Let's say there is a class called ParkingSpot with a public member Vehicle having an object type of object For simplicity, let's say that Vehicle could be anything, hence I create a new object of Car typ and assign it to...
2
8807
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 return type of a webmethod implement ISerializable? I saw something about using SoapInclude or XMLInclude attribute to include other types in web services. Does this imply that it is possible to return any type, even some third party class? ...
0
1649
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 class to a webservice, but I keep running into various problems. The latest one has to do with the fact that it requires me to use XMLInclude or SoapInclude. I'm fairly new to webservices so what I need is a small, clear sample how to create a...
1
421
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 call the webservice and pass it an Order, I get the following error message: The type Wright.BusinessLogicLayer.OrderLine was not expected. Use the
669
26263
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
2
6594
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){} I then determine what object I should call the Persist method on using a switch statement (not very OO). switch (otype)
3
7336
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 extanding these using partial classes on the client side to add in the business logic. This is all prety simple and works fine. What Im having a problem with is the deserialisation. The message I want to use is sent as raw XML enclosed within...
0
2625
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 multitude of web methods. All the web methods have various parameters, but one parameter which they all have in common is an 'object' parameter. This is due to the fact that the web service works differently according to the type of object being...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.