I've got a serializable type that wraps Dictionary< string,object> which I'm using to exchange payload.
In its deserialization constructor, we were using reflection to get the (private) Field m_nameToIndex from the given SerializationInfo and used it to get the values stored in another (private) Field called m_data.
Obviously it contained the key as well as the index of the value within m_data
public PayloadDictionary(SerializationInfo info, StreamingContext context)
{
_Dictionary = new Dictionary<string, object>();
var SIType = typeof(SerializationInfo);
var MI_nameToIndex = SIType.GetField("m_nameToIndex", BindingFlags.NonPublic | BindingFlags.Instance);
var MI_data = SIType.GetField("m_data", BindingFlags.NonPublic | BindingFlags.Instance);
Dictionary<string, int> nameToIndex = MI_nameToIndex.GetValue(info) as Dictionary<string, int>;
object[] data = MI_data.GetValue(info) as object[];
foreach (KeyValuePair<string, int> KV in nameToIndex)
{
var Object = data[KV.Value];
if (Object != null)
_Dictionary.Add(KV.Key, Object);
}
}
When the service has been compiled and deployed to a Windows Server 2012 R2, I can't seem to get the field m_nameToIndex using BindingFlags.NonPublic | BindingFlags.Instance anymore.
Sadly this is some old code from another developer and I don't really know why this is done manually in the first place.
Aucun commentaire:
Enregistrer un commentaire