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 2 3448
You could use the overload that takes a bool to see if there are any
exceptions that might help you.
One question though - are these two classes in the same assembly?
Regards,
Tim Haughton
"JohnnySparkles" <Jo************@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com... 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
No, they are in different assemblies, which is the problem.
I've worked out my problem, I needed to add the assembly name to the string
being used to create the type. Unoftunately the XmlSerializer doesn't
serialize this properly so I need to find some sort of work around for this.
It adds these __x0020 tags or something, any idea how to turn it off?
Cheers
Johnny
"Tim Haughton" wrote: You could use the overload that takes a bool to see if there are any exceptions that might help you.
One question though - are these two classes in the same assembly?
Regards,
Tim Haughton
"JohnnySparkles" <Jo************@discussions.microsoft.com> wrote in message news:F3**********************************@microsof t.com... 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jamie B |
last post by:
Is it possible to use System.Type, Activator or whatever to create a
complete "blank", unitialized object of a given type, and then at a later
time call a constructor on it. The only caveat is that...
|
by: Jim Bancroft |
last post by:
Hi everyone,
I'm having some trouble with the code below. I receive a compile-time
error on the second line saying "; expected":
private static void myTestFunction(long myLong)
{
...
|
by: Josh |
last post by:
Hi Guys,
I have hit a wall with the my project... The problem is that i need to get
the type of a usercontrol that is not in the assembly of the page that is
tryiong to call it. if anyone knows of...
|
by: Don |
last post by:
I have an array of System.type and I need to go through the array and
perform different logic depending on the type stored in the array.
I want to do:
if (typeof typeCollection(i) is String)...
|
by: Imran Aziz |
last post by:
Hello All,
I am getting the following error on our production server, and I dont
get the same error on the development box.
Unable to cast object of type 'System.Byte' to type 'System.String'.
...
|
by: JohnnySparkles |
last post by:
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,...
|
by: Sky |
last post by:
Yesterday I was told that GetType(string) should not just be with a Type, but
be Type, AssemblyName. Fair enough, get the reason. (Finally!).
As long as it doesn't cause tech support problems...
|
by: ceestand |
last post by:
I'm trying to make a change to an object depending contextually on it's type. The following code, even though I pass the Int32 into the function as an Object, still knows it's an Int32.
public...
|
by: Nathan Sokalski |
last post by:
I have the following code:
Dim values As New ArrayList()
values.Add("Yes")
values.Add("No")
values.Add("Maybe")
values.Add("Whatever")
dim x as String()=values.ToArray()
However, I recieve...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |