Hi all
I have a strange situation with a VS.net Add-In that uses the
XmlSerializer class for deserialization. In the code below, I pass a
given type to the serializer class. However, the type of the object that
is returned by the serializer is a different one so I can't get a
reference to it (casts fail).
//get the type -> same problem with typeof(...)
MappedObjectNode node = new MappedObjectNode();
Type type = node.GetType();
//store assembly location
string loc1 = type.Assembly.Location;
XmlSerializer serializer = new XmlSerializer(type);
using (Stream stream = file.OpenRead())
{
//perform deserialization
object obj = serializer.Deserialize(stream);
//get assembly location
string loc2 = obj.GetType().Assembly.Location;
}
When running this code, the strings loc1 and loc2 are different. VS.net
creates some kind of shadow copies for the add-in. However, the
serializer and the add-in use different assemblies:
loc1 (object created in add-in):
c:\dokumente und einstellungen\sumi\
lokale einstellungen\anwendungsdaten\assembly\
dl2\2dao39nh.tnl\4ehanxn5.m8y\
3bed8731\d814a9c3_828fc401\dao.net.dll
loc2 (object created by serializer):
c:\dokumente und einstellungen\sumi\
anwendungsdaten\microsoft\visualstudio\7.1\
projectassemblies\qcwp2ofq01\dao.net.dll
Strange enough, if I don't touch my solution and immediately open the
add-in, the copy within the "visualstudio\7.1"-folder is not being used
(loc1 and loc2 are the same as loc1 above) and my cast succeeds. This
works fine for me, but the add-in is part of an open-source project
which will hopefully be used by many people...
Right now, I'm stuck - any suggestion is highly appreciated
Thanks for your advice
Philipp