I have developped a custom XMLDeserializer which uses reflection to deserialize the content of my game (.xml). But I have an error that i don't figure it out when the content pipeline is compiling:
Error 1 Building content threw MethodAccessException: Attempt by security transparent method 'DynamicClass.ReflectionEmitUtils(System.Object)' to access security critical method 'System.Reflection.Assembly.get_PermissionSet()' failed.
Assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
The error doesn't occur if I comment out this code :
// Add item to the collection
if (typeof(IList).IsAssignableFrom(collectionType))
{
collectionType.GetMethod("Add").Invoke(collectionObject, new[] { itemObject });
}
else if (typeof(IDictionary).IsAssignableFrom(collectionType))
{
collectionType.GetMethod("Add").Invoke(collectionObject, new[] { itemType, itemObject });
}
It seems that my assembly does not have the permission to call code in mscorlib assembly. If i call my method in a console application, it works.
Can you help me?
Thanks