OK, I've investigated it further, and it looks like there's a problem
in our code.
DynamicProxy which is used under the cover by ActiveRecord generates
new proxy types to a in-memory assembly.
This assembly can be strong named, In your case, as all your types
aparently are in a strongly named assembly, DP decides that its in-
memory assembly should have a strong name as well, and as it turns
out, it can't do that in medium trust.

There's a flag - forceUnsigned that now defaults to false. We could
change that, so that it is true when we don't have the required
permission.

The stack trace shows that the exception is thrown in
http://msdn.microsoft.com/en-us/library/004y1sw8.aspx which requires
SecurityPermissionFlag.UnmanagedCode

Similarily to 
http://blogs.msdn.com/dmitryr/archive/2007/01/23/finding-out-the-current-trust-level-in-asp-net.aspx

we can write and use the following method to set the flag

private static bool CanUseStrongName()
{
        try
        {
                new 
SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand
();
                return true;
        }
        catch (SecurityException)
        {
                return false;
        }
}

This should get us all set.

Thoughts?

Donn - please create an issue in Donjon for that.

I don't have access to Visual Studio, so if someone wants to fix it -
go ahead.

Cheers,

Krzysztof

On 31 Sie, 15:28, Krzysztof Koźmic <[email protected]> wrote:
> can you verify that the assembly has the APTCA with reflector?
>
> Donn Felker wrote:
> > I've downloaded the latest from the trunk this morning and built the
> > source with the following command:
>
> > Code:
> > c:\...@svnrepositories\castle>SharedLibs\build\NAnt\bin\nant quick
> > release clean build -t:net-3.5 -D:assembly.allow-partially-trusted-
> > callers=true
>
> > This ended with this:
> > Code:
> > ...            BUILD SUCCEEDED
>
> >             Total time: 12 seconds.
>
> > BUILD SUCCEEDED - 2 non-fatal error(s), 0 warning(s)
>
> > Total time: 55.4 seconds.
>
> > When I run my site I get this:
> > Code:
>
> > 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.SecurityPermission,
> > 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.SecurityPermission, mscorlib,
> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
> > failed.]
> >    System.Reflection.StrongNameKeyPair..ctor(Byte[] keyPairArray) +28
> >    Castle.DynamicProxy.ModuleScope.GetAssemblyName(Boolean
> > signStrongName) +222
> >    Castle.DynamicProxy.ModuleScope.CreateModule(Boolean
> > signStrongName) +71
> >    Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithStrongName()
> > +126
> >    Castle.DynamicProxy.ModuleScope.ObtainDynamicModule(Boolean
> > isStrongNamed) +68
>
> > Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateTypeBuilder
> > (ModuleScope modulescope, String name, Type baseType, IEnumerable`1
> > interfaces, TypeAttributes flags, Boolean forceUnsigned) +103
> >    Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor
> > (ModuleScope modulescope, String name, Type baseType, IEnumerable`1
> > interfaces, TypeAttributes flags, Boolean forceUnsigned) +98
> >    Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor
> > (ModuleScope modulescope, String name, Type baseType, IEnumerable`1
> > interfaces) +53
> >    Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter
> > (String typeName, Type parentType, IEnumerable`1 interfaces) +112
>
> > Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateType
> > (String typeName, Type proxyTargetType, Type[] interfaces) +331
>
> > Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode
> > (Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions
> > options) +545
>
> > Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget
> > (Type interfaceToProxy, Type[] additionalInterfacesToProxy,
> > ProxyGenerationOptions options) +144
>
> > Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget
> > (Type interfaceToProxy, Type[] additionalInterfacesToProxy,
> > ProxyGenerationOptions options) +61
> >    Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
> > (Type interfaceToProxy, Type[] additionalInterfacesToProxy,
> > ProxyGenerationOptions options, IInterceptor[] interceptors) +329
> >    Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
> > (Type interfaceToProxy, IInterceptor interceptor) +129
>
> > Castle.Facilities.ActiveRecordIntegration.SessionFactoryDelegate.Create
> > (ISessionFactoryHolder sessionFactoryHolder, Type arType) +102
>
> > Castle.Facilities.ActiveRecordIntegration.ActiveRecordFacility.OnRootTypeRegistered
> > (Object sender, Type rootType) +510
> >    Castle.ActiveRecord.Framework.SessionFactoryHolder.Register(Type
> > rootType, Configuration cfg) +106
> >    Castle.ActiveRecord.ActiveRecordStarter.SetUpConfiguration
> > (IConfigurationSource source, Type type, ISessionFactoryHolder holder)
> > +372
> >    Castle.ActiveRecord.ActiveRecordStarter.Initialize
> > (IConfigurationSource source, Type[] types) +735
> >    Castle.ActiveRecord.ActiveRecordStarter.Initialize(Assembly[]
> > assemblies, IConfigurationSource source, Type[] additionalTypes) +197
>
> > Castle.Facilities.ActiveRecordIntegration.ActiveRecordFacility.InitializeFramework
> > (ArrayList assemblies) +841
> >    Castle.Facilities.ActiveRecordIntegration.ActiveRecordFacility.Init
> > () +986
> >    Castle.MicroKernel.Facilities.AbstractFacility.Init(IKernel kernel,
> > IConfiguration facilityConfig) +62
> >    Castle.MicroKernel.DefaultKernel.AddFacility(String key, IFacility
> > facility) +221
> >    Burst.DiligentLabs.WebHost.Application.RegisterFacilities(IKernel
> > kernel) +66
> >    Burst.DiligentLabs.WebHost.Global.Application_Start(Object sender,
> > EventArgs e) +177
>
> > Version Information: Microsoft .NET Framework Version:2.0.50727.4918;
> > ASP.NET Version:2.0.50727.4918
>
> > My mapping is set up as follows:
>
> > Code:
>
> > <facilities>
> >     <facility
> >         id="activerecord"
>
> > threadinfotype="Castle.ActiveRecord.Framework.Scopes.HybridWebThreadScopeInfo,
> > Castle.ActiveRecord"
> >         isDebug="false"
> >         isWeb="true"
> >         default-lazy="true"
> >         requirePermission="false">
>
> >       <!-- Medium Trust 
> > settings:http://nhforge.org/wikis/howtonh/run-in-medium-trust.aspx
> > -->
>
> >       <!-- Configure the namespaces for the models using Active Record
> > Intergration -->
> >       <assemblies>
> >         <item>Burst.DiligentLabs.WebHost</item>
> >       </assemblies>
>
> >       <config>
> >         <add key="connection.driver_class"
> > value="NHibernate.Driver.SqlClientDriver" />
> >         <add key="dialect"
> > value="NHibernate.Dialect.MsSql2005Dialect" />
> >         <add key="connection.provider"
> > value="NHibernate.Connection.DriverConnectionProvider" />
>
> >         <!-- Development -->
> >         <add key="connection.connection_string" value="Data Source=.
> > \SQLEXPRESS;AttachDbFileName=|DataDirectory|admin.mdf;Integrated
> > Security=True;User Instance=True;" />
>
> >         <add key="proxyfactory.factory_class"
> > value="NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> > NHibernate.ByteCode.Castle"/>
> >       </config>
>
> >     </facility>
>
> >   </facilities>
>
> > I've tried compiling without the tests (read the How TO Build file),
> > with tests, with specifying build targets, etc. I cannot get this to
> > work.
>
> > Does anyone see where I have the issue?
>
> > I"m testing this by placing <trust level="Medium" /> on my local dev
> > machine as my host is medium trust.
>
> > Thank you for any advice.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to