UnreferencedObjectEventArgs Class
Collapse the table of content
Expand the table of content

UnreferencedObjectEventArgs Class

Provides data for the known, but unreferenced, object found in an encoded SOAP XML stream during deserialization.


Namespace:  System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

public class UnreferencedObjectEventArgs : EventArgs

The UnreferencedObjectEventArgs type exposes the following members.

Public methodSupported by the XNA FrameworkUnreferencedObjectEventArgsInitializes a new instance of the UnreferencedObjectEventArgs class.

Public propertySupported by the XNA FrameworkUnreferencedIdGets the ID of the object.
Public propertySupported by the XNA FrameworkUnreferencedObjectGets the deserialized, but unreferenced, object.

Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)

For more information about the UnreferencedObjectEventArgs class, see the UnreferencedObject event of the XmlSerializer.

The UnreferencedObject event occurs only when you call the Deserialize method.

For more information about handling events, see Events Overview (Windows Forms)

The following example adds an UnreferencedObjectEventHandler to an XmlSerializer. The event is handled by the Serializer_UnreferencedObject method. To run the example, cut and paste the following XML into a file named UnrefObj.xml.

   <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" n1:GroupName=".NET" xmlns:n1="http://www.cpandl.com">
 <Vehicle id="id2" n1:type="Vehicle" xmlns:n1="http://www.w3.org/2001/XMLSchema-instance">
     <licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" n1:type="q1:string">ABCD</licenseNumber>
 <Vehicle id="id3" n1:type="Vehicle" xmlns:n1="http://www.w3.org/2001/XMLSchema-instance">
     <licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" n1:type="q1:string">1234</licenseNumber>

using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

// You must use the SoapIncludeAttribute to inform the XmlSerializer
// that the Vehicle type should be recognized when deserializing.
public class Group
   public string GroupName;
   public Vehicle GroupVehicle;
public class Vehicle
   public string licenseNumber;

public class Run
   public static void Main()
      Run test = new Run();

   public void DeserializeObject(string filename)
      // Create an instance of the XmlSerializer class.
      XmlTypeMapping myMapping = 
      (new SoapReflectionImporter().ImportTypeMapping(
      XmlSerializer mySerializer =  
      new XmlSerializer(myMapping);

      mySerializer.UnreferencedObject += 
      new UnreferencedObjectEventHandler

      // Reading the file requires an  XmlTextReader.
      XmlTextReader reader= 
      new XmlTextReader(filename);

      // Deserialize and cast the object.
      Group myGroup; 
      myGroup = (Group) mySerializer.Deserialize(reader);

   private void Serializer_UnreferencedObject
   (object sender, UnreferencedObjectEventArgs e){
      Console.WriteLine("ID: " + e.UnreferencedId);
      Console.WriteLine("UnreferencedObject: " + e.UnreferencedObject);
      Vehicle myVehicle = (Vehicle) e.UnreferencedObject;
      Console.WriteLine("License: " + myVehicle.licenseNumber);

// The file named "UnrefObj.xml" should contain this XML:

// <wrapper>

//  <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
//xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" 
//n1:GroupName=".NET" xmlns:n1="http://www.cpandl.com">
//   </Group>

//<Vehicle id="id2" n1:type="Vehicle" 
//   <licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" 
//   </Vehicle>

//<Vehicle id="id3" n1:type="Vehicle" 
//    <licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" 
//  </Vehicle>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

© 2015 Microsoft