C# SVN Pre Commit Hook, SharpSvn error

1k views Asked by At

I have a C# console application that I use as an SVN Pre Commit Hook. The console app is started perfectly. However, as soon as I try to do a Write using SharpSvn, I get this error:

Commit failed (details follow):
Commit blocked by pre-commit hook (exit code -1066598274) with output:

Unhandled Exception: System.Runtime.InteropServices.SEHException: External 
component has thrown an exception.
at svn_client_cat2(svn_stream_t* , SByte* , svn_opt_revision_t* , 
svn_opt_revision_t* , svn_client_ctx_t* , apr_pool_t* )
at SharpSvn.SvnClient.Write(SvnTarget target, Stream output, SvnWriteArgs args)
   at SharpSvn.SvnClient.Write(SvnTarget target, Stream output)
   at SvnPreCommitHook.Program.Main(String[] args)

I have tried to do the svn.Write command from my own machine, pointing to svn://svn-server instead of localhost - and that works fine. I guess it is something on the server. TortoiseSVN is installed, although I don't see any context menus...

My code looks like this:

private static EventLog _serviceEventLog;

static void Main(string[] args)
{
    _serviceEventLog = new EventLog();

    if (!System.Diagnostics.EventLog.SourceExists("Svn Hooks"))
    {
        System.Diagnostics.EventLog.CreateEventSource("Svn Hooks", "Svn Hooks");
    }

    _serviceEventLog.Source = "Svn Hooks";
    _serviceEventLog.Log = "Svn Hooks";

    SvnHookArguments ha;
    if (!SvnHookArguments.ParseHookArguments(args, SvnHookType.PreCommit, false, out ha))
    {
        /*Console.Error.WriteLine("Invalid arguments");
        Environment.Exit(1);*/
    }

    using (SvnLookClient cl = new SvnLookClient())
    {
        SvnChangeInfoEventArgs ci;
        cl.GetChangeInfo(ha.LookOrigin, out ci);

        if (!ci.LogMessage.Equals("Svn Hook Test"))
        {
            AllowCommit();

            return;
        }

        var checkoutDir = @"C:\SvnTemp\" + DateTime.Now.Ticks.ToString();

        foreach (SvnChangeItem i in ci.ChangedPaths)
        {
            var checkoutFilepath = checkoutDir + "\\" + Path.GetFileName(i.Path);

            if (!Directory.Exists(checkoutDir))
            {
                Directory.CreateDirectory(checkoutDir);
            }

            using (SvnClient svn = new SvnClient())
            {
                using (StreamWriter sw = new StreamWriter(checkoutFilepath))
                {
                    svn.Write(SvnTarget.FromString("svn://localhost/" + i.RepositoryPath), sw.BaseStream);
                }
            }

            var fileContents = File.ReadAllText(checkoutFilepath);

            if (fileContents.Contains("Martin Normark"))
            {
                RemoveTempDirectory(checkoutDir);

                PreventCommit("Name is not allowed!");
            }
        }

        RemoveTempDirectory(checkoutDir);
    }

    AllowCommit();
}
2

There are 2 answers

1
Daniel Hilgarth On

Maybe one of the following:

  • 64bit vs 32 bit
  • vcredist missing on the server
0
jreichert On

Maybe you should first catch the thrown exception by using the HandleProcessCorruptedStateExceptionsAttribute:

[HandleProcessCorruptedStateExceptions] 
static void Main() // main entry point
{
    try 
    {

    }
    catch (Exception ex)
    {
        // Handle Exception here ...
    }
}