0
votes

I have deployed WCF service on service on server and facing following exception.

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

Stack Trace:

[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner, StackCrawlMark& stackMark, Boolean skipVisibility) +160
   System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility) +40
   NHibernate.Bytecode.Lightweight.ReflectionOptimizer.CreateDynamicMethod(Type returnType, Type[] argumentTypes) +179
   NHibernate.Bytecode.Lightweight.ReflectionOptimizer.GenerateGetPropertyValuesMethod(IGetter[] getters) +326
   NHibernate.Bytecode.Lightweight.ReflectionOptimizer..ctor(Type mappedType, IGetter[] getters, ISetter[] setters) +150
   NHibernate.Bytecode.Lightweight.BytecodeProviderImpl.GetReflectionOptimizer(Type mappedClass, IGetter[] getters, ISetter[] setters) +62
   NHibernate.Tuple.Component.PocoComponentTuplizer..ctor(Component component) +367
   NHibernate.Tuple.Component.ComponentEntityModeToTuplizerMapping..ctor(Component component) +637
   NHibernate.Tuple.Component.ComponentMetamodel..ctor(Component component) +528
   NHibernate.Mapping.Component.BuildType() +65
   NHibernate.Mapping.Component.get_Type() +72
   NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping) +52
   NHibernate.Mapping.Property.IsValid(IMapping mapping) +56
   NHibernate.Mapping.PersistentClass.Validate(IMapping mapping) +139
   NHibernate.Mapping.RootClass.Validate(IMapping mapping) +45
   NHibernate.Cfg.Configuration.ValidateEntities() +241
   NHibernate.Cfg.Configuration.Validate() +30
   NHibernate.Cfg.Configuration.BuildSessionFactory() +61
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +49

Now I have applied below configuration and facing below problem:

<section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
     <section name="activerecord" requirePermission="false" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord"/>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
        <reflection-optimizer use="false" />
    </hibernate-configuration>

Stack Trace:

[SecurityException: That assembly does not allow partially trusted callers.]
   Castle.DynamicProxy.ModuleScope..ctor(Boolean savePhysicalAssembly, String strongAssemblyName, String strongModulePath, String weakAssemblyName, String weakModulePath) +0
   Castle.DynamicProxy.ModuleScope..ctor(Boolean savePhysicalAssembly) +35
   Castle.DynamicProxy.ProxyGenerator..ctor() +38
   NHibernate.ByteCode.Castle.ProxyFactory..cctor() +49
1

1 Answers

0
votes

Is your hosting provider only allowing you to run in medium trust? If so it means you can only reflect public members, I believe.

Rick Strahl talks medium trust here