Always use an absolute path when invoking Binsor

If, like me, you’re using Binsor for configuration, and using the include file mechanism to implement environmental deltas, you’re going to need to refer to the initial file using an absolute path.  The reason for this is, if you don’t, a relative path name within the Binsor script uses the current working directory.  Just to be annoying, this means that all of your code works until the moment you deploy it, and then your service fails to start (this bears no resemblance to a real issue, I can assure you…)

Anyway, here’s the code you need:

private static void ReadRelativePath(IWindsorContainer container, string relativePath)
    string location = System.Reflection.Assembly.GetEntryAssembly().Location;
    string directory = Path.GetDirectoryName(location);

    Rhino.Commons.Binsor.BooReader.Read(container, Path.Combine(directory, relativePath));

You could potentially fix this by changing the current directory in the program, but that’s the kind of externality I really don’t want to deal with.

Technorati Tags: ,

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s