【问题标题】:C# SVN Pre Commit Hook, SharpSvn errorC# SVN Pre Commit Hook, SharpSvn 错误
【发布时间】:2011-02-22 14:37:37
【问题描述】:

我有一个 C# 控制台应用程序,用作 SVN Pre Commit Hook。控制台应用程序完美启动。但是,一旦我尝试使用 SharpSvn 进行写入,我就会收到此错误:

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)

我试图从我自己的机器上执行 svn.Write 命令,指向 svn://svn-server 而不是 localhost - 效果很好。我想这是服务器上的东西。 TortoiseSVN 已安装,虽然我没有看到任何上下文菜单...

我的代码如下所示:

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();
}

【问题讨论】:

    标签: c# svn sharpsvn


    【解决方案1】:

    可能是以下之一:

    • 64 位与 32 位
    • 服务器上缺少vcredist

    【讨论】:

    • 机器和服务器都是x64的。
    【解决方案2】:

    也许您应该首先使用HandleProcessCorruptedStateExceptionsAttribute 捕获抛出的异常:

    [HandleProcessCorruptedStateExceptions] 
    static void Main() // main entry point
    {
        try 
        {
    
        }
        catch (Exception ex)
        {
            // Handle Exception here ...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多