Skip to content

Receiving System.AccessViolationException when attempting to commit #1444

Closed
@TheDrLamb

Description

@TheDrLamb

I am essentially trying to create just a simple test of the libgit2sharp library. I create new folders, add blank files to them, then stage, and attempt to commit the files; however, despite even having a catch block the program consistently responds with the error "'System.AccessViolationException' in LibGit2Sharp.dll" at the commit. I have tried this as the initial commit, as well as, for the directory after it has already had several commits to it. I am not entirely sure that I am using the library correctly, so I will attach my program below. Any help would be much appreciated.
`using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibGit2Sharp;
using LibGit2Sharp.Handlers;
using LibGit2Sharp.Core;

namespace GitMaker
{
class Program
{
static void Main(string[] args)
{
string root = @"C:\Users\ldawson\TestFolder";
string[] DirList = { "A","B","C","D"};

        /*for (int i = 0; i < DirList.Length; i++) {
            string path = System.IO.Path.Combine(root, DirList[i]);
            if (!Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
                //generates file for testing
                File.CreateText(path + "/Init");
            }
            // Create the new Repo at path
            Repository repo = CreateRepo(path);
            Console.WriteLine(repo.RetrieveStatus());
            //followed by git add/stage
            Stage(repo, path);
            Console.WriteLine(repo.RetrieveStatus());
            //then git commit
            Commit(repo);
        }*/

        //Test to see if it is simply the initial commit that is the issue
        //I will use a test dir "A" and add files to it and commit them
        string path = System.IO.Path.Combine(root, DirList[0]);
        Repository repo = new Repository(path);
        File.CreateText(path + "/Test1");
        Stage(repo, path);
        Commit(repo);
    }
    public static Repository CreateRepo(string path) {
        string repoPath = Repository.Init(path);
        Console.WriteLine(repoPath); //prints our path to the repo as a check
        Repository repo = new Repository(path);
        return repo;
    }
    public static void Commit(Repository repo) {
        Signature auto = new Signature("Automated", "@NotARealEmail", DateTime.Now);
        try
        {
            Signature author = auto;
            Signature commiter = auto;
            repo.Commit("Initial Commit", author, commiter);
        }
        catch (AccessViolationException e)
        {
            Console.WriteLine("Commit Failed:" + e.Message);
        }
    }
    public static void Stage(Repository repo,string path) {
        //add in options later to stage a single file or all changes
        try
        {
            using (repo)
            {
                //var files = System.IO.Directory.GetFiles(path);
                repo.Index.Add("Init");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Error with adding changes in the new Repo: " + e.Message);
        }
    }
}

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions