SecurityException - Dapper on shared hosting

In my current project, I am using Dapper. Everything is perfect. Then I needed to deploy it on shared hosting. The result can be seen here (copied YSOD):

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

Exception Details: System.Security.SecurityException: A permission request of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version = 4.0.0.0, Culture = Neutral, PublicKeyToken = b77a5c561934e089' failed.

Stack trace

[SecurityException: permission request of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' failed.] System.Security.CodeAccessSecurityEngine.Check (demand object, StackCrawlMark & ​​Stack 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 Dapperx.SqlMapper.CreateParamInfoGenerator (Identity identity) +537 Dapperx.SqlMapper.GetCacheInfo (Identity +376 Dapperx.d__13 1.MoveNext() +644
System.Collections.Generic.List
1.MoveNext() +644
System.Collections.Generic.List
1.MoveNext() +644
System.Collections.Generic.List
1..ctor (IEnumerable 1 collection) +327 System.Linq.Enumerable.ToList(IEnumerable 1 source) +58
Dapperx.SqlMapper.Query (IDbConnection cnn, String sql, object parameter, IDbTransaction transaction, Boolean buffering, Nullable 1 commandTimeout, Nullable 1 commandType) +199
...

Is there a way to solve this problem (in .NET 4.0)? As far as I understand, what I read so far, the provider should allow some parts from reflection for IIS, which may pose a security risk to them ...

+4
source share
1 answer

Reflection.Emit, which is used by Dapper, is not allowed in the Medium Trust.

You should find a hosting provider that offers Full Trust. discountasp.net is the one I used before.

+1
source

Source: https://habr.com/ru/post/1414673/


All Articles