(Free) NHibernate Security Exception - ReflectionPermission
I have updated my ASP.Net web application to the latest Fluent NHibernate build (1.0.0.636) and the newest NHibernate version (v2.1.2.4000). I have checked a couple of times that the application is running in full trust mode. But I keep getting the following error:
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 trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner, StackCrawlMark& stackMark, Boolean skipVisibility) +269
System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility) +81
NHibernate.Bytecode.Lightweight.ReflectionOptimizer.CreateDynamicMethod(Type returnType, Type[] argumentTypes) +165
NHibernate.Bytecode.Lightweight.ReflectionOptimizer.GenerateGetPropertyValuesMethod(IGetter[] getters) +383
NHibernate.Bytecode.Lightweight.ReflectionOptimizer..ctor(Type mappedType, IGetter[] getters, ISetter[] setters) +108
NHibernate.Bytecode.Lightweight.BytecodeProviderImpl.GetReflectionOptimizer(Type mappedClass, IGetter[] getters, ISetter[] setters) +52
NHibernate.Tuple.Component.PocoComponentTuplizer..ctor(Component component) +231
NHibernate.Tuple.Component.ComponentEntityModeToTuplizerMapping..ctor(Component component) +420
NHibernate.Tuple.Component.ComponentMetamodel..ctor(Component component) +402
NHibernate.Mapping.Component.BuildType() +38
NHibernate.Mapping.Component.get_Type() +32
NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping) +39
NHibernate.Mapping.RootClass.Validate(IMapping mapping) +61
NHibernate.Cfg.Configuration.ValidateEntities() +220
NHibernate.Cfg.Configuration.Validate() +16
NHibernate.Cfg.Configuration.BuildSessionFactory() +39
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:93
Has anyone had the same error? I have been browsing the web / stackoverflow / NHibernate forums but found people who had the problem when running in medium trust mode rather than full trust. I've been developing this application on this machine for several months now with previous versions of Fluent NHibernate and NHibernate.
The machine I am running this on is 64 bit, you never know this is up to date.
source to share
When you load a new DLL for the first time, you might have this problem, it might not be your problem (something that makes it unreliable causes the same error), but it threw the exact error for me more than once. Here's how to get it back in full trust like all other apps:
- Right click the new nHibernate dlls (you may need to do this 1 at a time, not sure)
- Properties
- At the very bottom of the General tab , you can see the message: "This file came from another computer and may be blocked to protect this computer."
- Click Unblock next to this
source to share