I have joined Anti-IF Campaign

This has caused me a lot of pain today so I thought that I would share my findings!

If you intend to publish your site to shared hosting and they are restricting you to a Medium trust security policy (which is expected really on shared hosting) you need to have assemblies that work properly!

After finding the issue the first thing I did was to get a dev environment that replicated the problem. The easiest way to do this is to set the trust level in the web.config. You can do this by adding this within the system.web  element:

<system.web>
<trust level=”Medium”/>

…other tastey elements…..

</system.web>

In the future I will set this before I start programming anything - probably good practice when you know you will be deploying to a medium trust environment but I will put that down to a lesson learnt!

After that you need to build Castle from source with a few additional parameters to make it run in medium trust. To do this you need to check it out from SVN. I had a few problems here too with SVN externals. I ended up getting the latest version of tortoise and checking it out on a Windows 7 VM I had running.
Check it out from here: http://svn.castleproject.org:8080/svn/castle/trunk/

Once fully checked out, open a cmd promt and navigate to the the root of the checked out directory. run this command:
build.cmd -D:assembly.allow-partially-trusted-callers=true release quick build

Watch the window for any errors and please read the error messages if you get any. I got one in relation to not having the .NET 2.0 SDK installed, so guess what - I installed it and tried again and it worked!

OK great now we have some assemblies that will run under medium trust. Copy these over the old versions and make sure you perform a clean build. Thats Castle sorted right? WRONG! It still won’t work.

I then had an issue with Castle.Service.Transations. Read this for more information (http://stackoverflow.com/questions/1038914/using-castle-windsor-and-the-nhibernate-facility-on-shared-hosting). OK no probs got that sorted by registering it in my container:

container.Register(Component
.For(typeof (IActivityManager))
.ImplementedBy(typeof (TLSActivityManager)));

OK we are still not there - a couple more things to do in the web.config. You need to add the requirePermission=”false” attribute the the castel section:

<section name=”castle” requirePermission=”false” type=”Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor”/>

I also disabled the NHibernate reflection optimiser:

<item key=”reflection-optimizer”>false</item>

OK almost there - the app will now run. Next was the problem of URL’s and the fact I was not allowed a wild card mapping - fine - no probs, lets update the routing. I changed my routing to the following:

routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new {controller = "Home", action = "Index", id = ""},
new[] {”ANAMESPACE.Core.Controllers”});

Yay! That works! There is only one more problem. If I go to / then it can’t find a route regardless of the default file settings. So a bit of a workaround was to add another route after the usual default:

routes.MapRoute(
"",
new { controller = "Home", action = "Index", id = "" },
new[] { “ANAMESPACE.Core.Controllers” });

This feels very wrong and I don’t like it! There must be a better way.

Anyway - screw you shared hosting and medium trust!

5 Comments | Category: .NET, C#, Castle, IIS, MVC.NET, NHibernate

Thanks to Martin Gleadow:

stick this in your ~/.screenrc and smoke it

escape ^gg
hardstatus alwayslastline "%{=b}%{kG}|g| %H | %t |%{kb} %w %=%{G}| %C%A"

the first line turns Ctrl-G into your attention character
the second line makes the following appear at the bottom of your screen:

|g| $server | $current_window | 0* $windowname ... n $windowname | hh:mm

No Comments | Category: Unix

WinSplit Revolution is a small utility which allows you to easily organize your open windows by tiling, resizing and positioning them to make the best use of your desktop real estate.

http://www.winsplit-revolution.com/

No Comments | Category: Windows'y stuff

This makes managing SQL server so much easier - especially when you have a HUGE sql file to run and enterprise manager won’t even open it for you!

SQLCMD/? will give you all the options available.

An example of piping in a file to a defined instance using a a username and password:

SQLCMD -S localhost\SQLSERVER2005 -U username -P password -i sql-file-to-run.sql

easy peasy! Just make sure the user you are logging in as has all of the permissions required to perform all of the actions in the sql file! (watch the console output!)

No Comments | Category: SQL Server, SQL Server 2005

http://www.my-debugbar.com/wiki/IETester/HomePage

No Comments | Category: Uncategorized

I found this very useful today. I have a Quatz Job running that requires access to a repository. This repository is usually resolved by castle like so:

var repository = Registry.Get<MyRepository>();

In the case I have I cannot do this as ‘MyRepository’ depends on having an ISessionManger injecting into it but in this context one does not exists. What I found out though (thanks to Thom) was that I can simply ask the container for an ISessionFactory like so:

var sessionFactory = Registry.Get<ISessionFactory>();

Now I can create a class that implements ISessionManager and instantiate my repository with this - top stuff!

Now I have found this I will be changing how my integration tests work!

No Comments | Category: .NET, Castle

At first I thought this may be tricky but as it turns out I am not the only one ever to have this problem!

First of all you can try and use the SpecificPickupDirectory. This tells the smtp client to simply drop the message into a desegnated directory:

http://dotnettipoftheday.org/tips/smtp-delivery-method-SpecifiedPickupDirectory.aspx

<system.net>

<mailSettings>

<smtp deliveryMethod=”SpecifiedPickupDirectory”>

<specifiedPickupDirectory pickupDirectoryLocation=”c:\Test\” />

</smtp>

</mailSettings>

</system.net>


If that does not float your boat then you can take it a stage further:

http://haacked.com/archive/2006/05/30/ATestingMailServerForUnitTestingEmailFunctionality.aspx

Another useful tool is this: http://www.codeproject.com/KB/IP/despop3client.aspx

No Comments | Category: .NET, Testing

http://reflectoraddins.codeplex.com/Wiki/View.aspx?title=CodeMetrics

No Comments | Category: .NET, C#

I am currently working on a new project and I am going full on TDD and BDD (where appropriate). As I have been in a variety of different environments I want to be able to check out the project, run the tests and write some code. My integration tests rely on a database (currently proving that my nhibernate mappings are correct) and I did not want there to be a dependency on having a database running so I wanted to use sqlite.

Here is what I did:

Download sqlite:

http://sourceforge.net/projects/sqlite-dotnet2

Get an sqlite GUI admin tool:

http://sqliteadmin.orbmu2k.de/

Create a database to connect to.

Change you nhibernate config file:

<?xml version="1.0" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.SQLiteDialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.SQLite20Driver
</property>

<property name="connection.connection_string">
Data Source=directory-in-your-test-assembly\your-database.s3db
</property>

<property name="query.substitutions">true=1;false=0</property>

<mapping assembly="YourAssembly" />

</session-factory>
</hibernate-configuration>

Notice that I have used the SQLite20Driver instead of SQLiteDriver (it won’t work otherwise!)

Don’t forget to make sure that your db is copied to your output directory.

I will expand upon this post tomorrow when I have more time!

No Comments | Category: .NET, ActionScript 3

http://weblogs.asp.net/bleroy/archive/2009/05/13/new-release-of-the-ajax-control-toolkit.aspx

No Comments | Category: .NET