This line of code :
var user = users.SingleOrDefault(u => u.EmailAddress == form.EmailAddress);
where users is a collection of
public class User
{
[Key, Required]
public string EmailAddress { get; set; }
public string PasswordHash { get; set; }
public string PasswordSalt { get; protected set; }
}
is producing an exception when in medium trust level.
Is there a way to make it works in this trust level?
I tried signing my assemblies with a key but the problem is still there.
I am using Entity Framework and ASP.NET 4.0.
I cannot change the trust level (the code is working fine in full trust).
Here’s the exception Stack:
SecurityException: Richiesta di autorizzazione di tipo 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' non soddisfatta.]
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.Data.Common.Internal.Materialization.Translator.DemandMemberAccess() +50
System.Data.Common.Internal.Materialization.Shaper`1..ctor(DbDataReader reader, ObjectContext context, MetadataWorkspace workspace, MergeOption mergeOption, Int32 stateCount, CoordinatorFactory`1 rootCoordinatorFactory, Action checkPermissions, Boolean readerOwned) +165
System.Data.Common.Internal.Materialization.ShaperFactory`1.Create(DbDataReader reader, ObjectContext context, MetadataWorkspace workspace, MergeOption mergeOption, Boolean readerOwned) +93
System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +736
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +149
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44
System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +184
System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2(IEnumerable`1 sequence) +41
System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +59
System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +150
System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +102
System.Linq.Queryable.SingleOrDefault(IQueryable`1 source, Expression`1 predicate) +300
What is the users class? Is that EF or you own? If it’s yours add
AllowPartiallyTrustedCallersAttributeto it.