The problem I am trying to solve is that, I need to serialize the Entity's Target/Pre/Post-Image into a json string. I know that we cannot include nuget libraries in the plugins as ILmerge is not an option. This is the one i have tried:
var jStr = Serialize((Entity)excutionContext.InputParameters["Target"]);
public static string Serialize<TEntity>(TEntity dataObject)
{
using (var stream = new MemoryStream())
{
var serializer = new DataContractJsonSerializer(typeof(TEntity));
serializer.WriteObject(stream, dataObject);
return Encoding.UTF8.GetString(stream.ToArray());
}
}
But i am getting the following exception and unable to figure out what i do to solve the same:
System.Security.SecurityException: 'The data contract type 'System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' cannot be serialized in partial trust because the member 'key' is not public.'