Sql Persistence 3.0 installer and website

sql-persistence

(Laurent Nullens) #1

When used in an web site, the installers fail due to a location issue.
The installer is expecting the script folder to be in the root folder and not in the bin, where they are.
It was working in 2.1.4 and is broken in version 3.

code was:

public static string FindScriptDirectory(SqlVariant sqlVariant)
{
    string codeBase = Assembly.GetExecutingAssembly().CodeBase;
    string currentDirectory = Directory.GetParent((new Uri(codeBase)).LocalPath).FullName;
    return Path.Combine(currentDirectory, "NServiceBus.Persistence.Sql", sqlVariant.ToString());
}

and now:

public static string FindScriptDirectory(ReadOnlySettings settings)
{
    var currentDirectory = GetCurrentDirectory(settings);
    return Path.Combine(currentDirectory, "NServiceBus.Persistence.Sql", settings.GetSqlDialect().Name);
}

static string GetCurrentDirectory(ReadOnlySettings settings)
{
    if (settings.TryGet("SqlPersistence.ScriptDirectory", out string scriptDirectory))
    {
        return scriptDirectory;
    }
    var entryAssembly = Assembly.GetEntryAssembly();
    if (entryAssembly == null)
    {
        return AppDomain.CurrentDomain.BaseDirectory;
    }
    var codeBase = entryAssembly.CodeBase;
    return Directory.GetParent(new Uri(codeBase).LocalPath).FullName;
}

(Szymon Pobiega) #2

Yeah, it definitely looks like a bug. Thanks for reporting it. We’ll fix it. In the meantime you can set the “SqlPersistence.ScriptDirectory” setting via EndpointConfiguration to point to the correct directory.

Szymon