I have this code:
// Create and deserialize a ViewletMetabase object..
XmlSerializer serializer = new XmlSerializer(typeof(ViewletMetabase));
MemoryStream ms = new MemoryStream(File.ReadAllBytes(MetabaseFileName));
Object obj serializer.Deserialize(ms);
// At this point, obj is NOT null
ViewletMetabase vm = obj as ViewletMetabase;
// At this point vm is null!?!?!? WTF?
If I use reflection, I can interact with obj as
a ViewletMetabase - but it will NOT cast to a ViewletMetabase.
'obj is ViewletMetabase' returns false.
How is this possible?
As a little bit of background. This code is running inside of the VisualStudio 2010 process itself, as part of a UITypeEditor - but I can't for the life of me understand how this could actually be relevant. Regardless of where this code is running, how can I pass typeof(ViewletMetabase) into an XmlSerializer object, deserialize a stream, and then get back an object that is not of type ViewletMetabase 3 lines later within the same method?
Any suggestions greatly appreciated.