AutoMapper throwing Security exception for ReflectionPermission

jestrik

Guppy
I'm using AutoMapper in a project i've been developing on my hosting space to map between domain entities and DTOs.

I've stupidly been developing this in full trust and have now come to running it on my hosting space and it's throwing a SecurityException for the ReflectionPermission. This is because AutoMapper emits reflection code.

I'm wondering if there's any chance I can have this permission allowed on my account?

Thanks
James
 
which exact reflection permission is needed? We allow 'ReflectionEmit and RestrictedMemberAccess' (that last one is LINQ required)
 
Hi Stephen,

I'm not sure exactly, it's throwing the exception when creating a new DynamicMethod instance -

private static DynamicMethod CreateDynamicMethod(MemberInfo member, Type sourceType)
{

...

return new DynamicMethod("Set" + member.Name, null, new[] { typeof(object), typeof(object) }, sourceType, true);

...
}


Here's the error -

Server Error in '/' Application.
--------------------------------------------------------------------------------

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
System.Security.CodeAccessPermission.Demand() +46
System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner, StackCrawlMark& stackMark, Boolean skipVisibility) +9461551
System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility) +40
AutoMapper.DelegateFactory.CreateDynamicMethod(MemberInfo member, Type sourceType) +682
AutoMapper.DelegateFactory.CreateSet(PropertyInfo property) +139
AutoMapper.Internal.PropertyAccessor..ctor(PropertyInfo propertyInfo) +153
AutoMapper.ReflectionHelper.ToMemberAccessor(MemberInfo accessorCandidate) +341
AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options) +554
AutoMapper.ConfigurationStore.CreateTypeMap(Type source, Type destination, String profileName) +166
AutoMapper.ConfigurationStore.CreateMap(String profileName) +194
AutoMapper.ConfigurationStore.CreateMap() +115
AutoMapper.Mapper.CreateMap() +122
Bywater.ServiceLayer.ObjectMapper..cctor() +66




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1


Do you need more information?

Thanks
James
 
Back
Top