About your host

Photo of your host - Charles Vallance Charles Vallance is a web developer with a slight case of OCD when it comes to nice clean standards compliant html and code.

Badges

twitter / cvallance
My articles have been featured in The Morning Brew - Daily .NET News and Views

Tag Cloud

more tags...
posted @ Wednesday, November 07, 2007 9:11 PM

I've been wanting to make a site using the Castle Project for a while now and I finally took some time out yesterday to give it a whirl. First impressions, awesome... I can't wait to get fully stuck into it! Which should be about 1 minute after writing this! :-)

I've just finished using CakePHP for a big project, so MonoRail's MVC way of thinking isn't foreign to me. I've also been wanting to have a look at NHibernate and ActiveRecord is built on top of NHibernate so I can get a bit of a low down on how NHibernate works too. I'll have to get to grips with this NVelocity view engine thou... it seems easy enough when I follow the tutorials but they're obviously not that complicated! ;-)

So anyway, I got MonoRail and ActiveRecord working fine on my local machine by downloading the RC2 MSI installer from their site and creating a new project inside VS. But when I then tried to upload this site to my shared host (KiwiHosting), it spat out this exception:

[SecurityException: That assembly does not allow partially trusted callers.]

After some searching on the net I found this forum message that related to the exception. In there it said that I needed to compile it again from the source files, but this time allowing support for shared environments (partially trusted).

So I then downloaded the source code to do this build and then found that I had to use NAnt to build it, so I went and got that too. To build castle with support for shared environments you must run this:

nant -D:assembly.allow-partially-trusted-callers=true

But when I ran that line I would get a build error like this:

CastleKey.snk missing

Cannot find 'CastleKey.snk' huh? Hmmm... I remembered that inside the 'How to buil.txt' file that came with the source you could add '-D:sign=false' to compile a version that wasn't strongly signed. So I tried that... it seemed to get a bit further but again didn't make it.

After some more searching I found a site (can't find it again today) that said you can't actually build it without the 'CastleKey.snk' file and that it was inside the Castle Subversion Repositry. So I checkout the repository to my local machine and finally the build worked! Then replaced all my references within VS, did another build of my own site, uploaded it and voila! Castle was working on my shared hosting environment!

So, just to recap on the process required to get castle up and running on a shared hosting enviroment1:

  1. Check out the Castle Subversion repositry to a local directory. Note: Make sure there are no spaces in any of the directory names, eg. C:\Program Files\Castle\repo won't work.
  2. Download NAnt (was at version 0.85 at time of writing) and extract the files to your hard drive.
  3. Add the bin directory for NAnt to your 'Path' system variable2.
  4. From the command prompt inside your Castle Subversion repository directory type:
    nant -D:assembly.allow-partially-trusted-callers=true
    All the compiled assemblies can now be found in a build directory under your castle subversion repository.
  5. Create a new blank project inside VS and add references to the following freshly compiled assemblies.

    For MonoRail:

    1. Castle.MonoRail.Framework.dl
    2. Castle.MonoRail.Framework.Views.NVelocity.dll
    3. Castle.Components.Binder.dll
    4. Castle.Components.Common.EmailSender.dll
    5. Castle.Core.dll
    6. NVelocity.dll

    For ActiveRecord:

    1. Castle.ActiveRecord.dll
    2. Castle.DynamicProxy.dll
    3. Iesi.Collections.dll
    4. log4net.dll
    5. NHibernate.dll
  6. Unless you can convince your hoster to map .rails extensions to the ASP.Net ISAPI you should also edit/add this to your web.config file with this:
<httpHandlers>
    <add verb="*" path="*.ashx"
        type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" />
</httpHandlers>
  1. Now you have to make sure all your files link to the ashx extension.

I think thats about all there is to it... Bring on RC3!

1 This excludes a lot of the general setup for a castle project, including a lot of the web.config settings. Visit the castle home page and go to 'getting started' to find out more.

2 If you don't know how to do this I explained this in my last post in regards to adding the svn bin directory to the 'Path' system variable.

Technorati Tags: ,

And then he said...

# re: Castle on a Shared Hosting Environment

Gravatar
Posted by Alex Egg
on 8/14/2007 4:08 PM
thank you for this!! You're my hero! blogs are so amazing...

I hope this works about about to try it.

# re: Castle on a Shared Hosting Environment

Gravatar
Posted by Alex Egg
on 8/14/2007 5:08 PM
Hi, I can confirm this works, future users will probably want to build with the unit tests disabled with this switch:

nant -D:assembly.allow-partially-trusted-callers=true -D:common.testrunner.enabled=false

I was not able to successfully build until I turned off the tests.

In addition, some users who are doing shared hosting with go daddy will need to recompile the MySQL.Data.dll with this attribute in the AssemblyInfo.cs:

[assembly: AllowPartiallyTrustedCallers]

The source comes in the download for the MySql Connector.net from the mysql website. It even comes with the vs project file so recompiling it is a snap.

# re: Castle on a Shared Hosting Environment

Gravatar
Posted by Alex Egg
on 8/14/2007 5:08 PM
I guess I should have mentioned:

MySql.data.dll is only needed if your using MySql with Castle's ActiveRecord...

# re: Castle on a Shared Hosting Environment

Gravatar
Posted by charles
on 8/15/2007 10:08 PM

Hi Alex,<br />
Thanks for reminding me about that, at the time of posting this it did work!


When I found them failing agian, I went over this page - using.castleproject.org/.../Using+the+Trunk - again and did exactly what you have suggested.


My bat file current looks like this:


nant -t:net-2.0 -D:assembly.allow-partially-trusted-callers=true -D:common.testrunner.enabled=false


Works a treat for me!


And then I said...

Title *
Name *
Email
Url
Comment *  
Please add 8 and 2 and type the answer here: