G
Guest
Hi everyone,
I'm currently writing an application which uses the XmlSerializer class to
serialize/deserialize objects to/from xml.
Now when deserializing an XmlDocument back into the object, I'm using the
System::Type::GetType(String* typeName) to create a Type* needed to construct
the XmlSerializer.
The typeName argument is taken from the XmlDocument and consists of the
Namespace of the class and the class name (i.e. "System.Type"). I add this as
an XmlRootAttribute to the class because XmlSerializer will typically
serialize objects with only the class name and not the namespace, which is
required for GetType(). I then retrieve this String when deserializing the
object and use it to create a Type*.
This has been working fine until I began to pass the XmlSerializer objects
which were not from the same namespace as the class which is making the
System.Type.GetType() call. When I call the System.Type.GetType() it returns
null, even though the type is known by the class and the class also includes
the namespace the type is declared in.
For example:
namespace namespace1
{
[XmlRootAttribute("namespace1.serializeClass")]
public __gc class serializeClass
{
//Data members, constructors etc...
};
}
//Another File:
#using "namespace1.dll"
namespace namespace2
{
using namespace namespace1;
[XmlRootAttribute("namespace2.serializeClass2")]
public __gc class serializeClass2
{
//Data members, constructors, etc...
};
public __gc class serializer()
{
System::Type* type1 = System::Type::GetType("namespace2.serializeClass2");
//Will return a valid System.Type
System::Type* type2 = System::Type::GetType("namespace1.serializeClass");
//Will return null
}
}
Does anyone have any ideas as to why this might be happening?
Cheers
Johnny
I'm currently writing an application which uses the XmlSerializer class to
serialize/deserialize objects to/from xml.
Now when deserializing an XmlDocument back into the object, I'm using the
System::Type::GetType(String* typeName) to create a Type* needed to construct
the XmlSerializer.
The typeName argument is taken from the XmlDocument and consists of the
Namespace of the class and the class name (i.e. "System.Type"). I add this as
an XmlRootAttribute to the class because XmlSerializer will typically
serialize objects with only the class name and not the namespace, which is
required for GetType(). I then retrieve this String when deserializing the
object and use it to create a Type*.
This has been working fine until I began to pass the XmlSerializer objects
which were not from the same namespace as the class which is making the
System.Type.GetType() call. When I call the System.Type.GetType() it returns
null, even though the type is known by the class and the class also includes
the namespace the type is declared in.
For example:
namespace namespace1
{
[XmlRootAttribute("namespace1.serializeClass")]
public __gc class serializeClass
{
//Data members, constructors etc...
};
}
//Another File:
#using "namespace1.dll"
namespace namespace2
{
using namespace namespace1;
[XmlRootAttribute("namespace2.serializeClass2")]
public __gc class serializeClass2
{
//Data members, constructors, etc...
};
public __gc class serializer()
{
System::Type* type1 = System::Type::GetType("namespace2.serializeClass2");
//Will return a valid System.Type
System::Type* type2 = System::Type::GetType("namespace1.serializeClass");
//Will return null
}
}
Does anyone have any ideas as to why this might be happening?
Cheers
Johnny