Compiling Castle stack with partial trust.

20 views
Skip to first unread message

Mike Cameron

unread,
Nov 11, 2010, 3:32:36 PM11/11/10
to Castle Project Users
Before anyone asks, yes, this is a crosspost from SO which can be
found at http://stackoverflow.com/questions/4148394/compiling-castle-activerecord-to-allow-partial-trust.

Here is my problem. I have a C# Windows Forms application created
using the latest stable version of Castle.ActiveRecord (2.1.0 and
NHibernate. This application needs to be run from a shared file server
running under medium trust. As I'm sure you're aware Castle doesn't
play nice under medium trust. Below are the steps I followed.

- Downloaded NHibernate 2.1.2GA and built with `nant D:assembly.allow-
partially-trusted-callers=true`
- Downloaded Castle.Core 1.2.0 (https://github.com/castleproject/
Castle.Core/tree/1.2.0) and built with `nant -D:assembly.allow-
partially-trusted-callers=true -D:common.testrunner.enabled=false`
- Moved newly built Castle.Core.dll to Castle.ActiveRecord\lib\net35
- Built Castle.ActiveRecord with `nant -D:assembly.allow-partially-
trusted-callers=true -D:common.testrunner.enabled=false`

All compiles and publishes fine however I get this lovely
SecurityException "Request for the permission of type
'System.Data.SqlClient.SqlClientPermission, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.". I'm using Sql Server 2000.

What am I doing wrong?

Roelof Blom

unread,
Nov 12, 2010, 4:11:10 AM11/12/10
to castle-pro...@googlegroups.com
Hi Mike,

From your error it seems you are using ActiveRecord w/ LazyLoad. If so, if you disable that is the error going away?

Also, please send a full stacktrace and as much information as you can as the crystal balls are shut down here for the weekend.

-- Roelof.


--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.


Mike Cameron

unread,
Nov 12, 2010, 10:26:08 AM11/12/10
to Castle Project Users
My stacktrace is as follows.

" at System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)\r\n at
System.Security.PermissionSet.Demand()\r\n at
System.Data.Common.DbConnectionOptions.DemandPermission()\r\n at
System.Data.SqlClient.SqlConnection.PermissionDemand()\r\n at
System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection
outerConnection)\r\n at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)\r\n at
System.Data.SqlClient.SqlConnection.Open()\r\n at
NHibernate.Connection.DriverConnectionProvider.GetConnection()\r\n
at
NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare()
\r\n at
NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect
dialect, IConnectionHelper connectionHelper)\r\n at
NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory
sessionFactory)\r\n at
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping
mapping, Settings settings, EventListeners listeners)\r\n at
NHibernate.Cfg.Configuration.BuildSessionFactory()\r\n at
Castle.ActiveRecord.Framework.SessionFactoryHolder.GetSessionFactory(Type
type)\r\n at
Castle.ActiveRecord.Framework.SessionFactoryHolder.CreateSession(Type
type)\r\n at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type
targetType, DetachedCriteria detachedCriteria, Order[] orders)\r\n
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType)\r\n
at Castle.ActiveRecord.ActiveRecordBase`1.FindAll()\r\n at
TxLocates.TxLocate..ctor()\r\n at TxLocates.Program.Main()\r\n at
System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r
\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)\r\n at System.Runtime.Hosting.ManifestRunner.Run(Boolean
checkAptModel)\r\n at
System.Runtime.Hosting.ManifestRunner.NewThreadRunner()\r\n at
System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n
at System.Threading.ExecutionContext.runTryCode(Object userData)\r\n
at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object userData)\r\n at
System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state)\r\n at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)\r\n at
System.Threading.ThreadHelper.ThreadStart()"

This exception still persits with Lazy = false on all my entities.

On Nov 12, 4:11 am, Roelof Blom <roelof.b...@gmail.com> wrote:
> Hi Mike,
>
> From your error it seems you are using ActiveRecord w/ LazyLoad. If so, if
> you disable that is the error going away?
>
> Also, please send a full stacktrace and as much information as you can as
> the crystal balls are shut down here for the weekend.
>
> -- Roelof.
>
> On Thu, Nov 11, 2010 at 9:32 PM, Mike Cameron
> <michael.came...@hydroone.com>wrote:
>
>
>
>
>
>
>
> > Before anyone asks, yes, this is a crosspost from SO which can be
> > found at
> >http://stackoverflow.com/questions/4148394/compiling-castle-activerec...
> > .
> > castle-project-u...@googlegroups.com<castle-project-users%2Bun subs...@googlegroups.com>
> > .

Mike Cameron

unread,
Nov 12, 2010, 1:24:51 PM11/12/10
to Castle Project Users
All is fixed. Turns out my assemblies had all properly been compiled
however my VS2008 solution still needed some minor tweaks.

Roelof, your help is much appreciated.

Roelof Blom

unread,
Nov 12, 2010, 2:10:12 PM11/12/10
to castle-pro...@googlegroups.com
You're welcome. Care to share your tweaks?

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Mike Cameron

unread,
Nov 12, 2010, 3:14:29 PM11/12/10
to Castle Project Users
Good call.

Almost all of my tweaks were done in the Security tab under project
properties.

- Under the "Zone your application will be installed from:" label I
selected "(Custom)"
- As for the permissions required by the application, I had to include
SqlClientPermission as well as UIPermission. In order to negate
problems for future development I selected "Grant assemblies
unrestricted access to x" where is the selected permission. That was
done for both permissions shown above. Note that the permissions you
select to include will be on a per application basis and no two cases
will be the same.
- Under the "Advanced..." button I unselected both options ("Debug
this application with the selected permission set" and "Grant the
application access to its site of origin").

Also, since the application and SQL Server are residing under
different domains I had to set my connection string to include the
database server domain. So my original connection string data source
had to go from "Data Source=DB_SERVER" to "Data
Source=DB_SERVER.DOMAIN".

Lastly, I had to set `requirePermission="false"` on all of my
configuration sections. My `configSections` ended up like this:

<configSections>
<section name="activerecord"
type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler,
Castle.ActiveRecord" requirePermission="false"/>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"
requirePermission="false"/>
<section name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System,
Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
<section name="hibernate-configuration" requirePermission="false"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>

After everything was said and done I was successfully able to publish
this application on a file share from a different domain and have the
users install the application with no issues. Applying these steps to
our other applications and using our newly compiled assemblies also
worked like a charm.

Again, thanks for the help. :)

Roelof Blom

unread,
Nov 12, 2010, 3:16:24 PM11/12/10
to castle-pro...@googlegroups.com
Thanks for sharing.


--
Reply all
Reply to author
Forward
0 new messages