libgit2 / libgit2/libgit2sharp
Repository.Discover() throws exception in Release mode, but not Debug mode
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
I'm making a VSIX extension that does Git operations, I ran into this issue while trying to get the corresponding repo for the active document. When testing in the LLVM repo, doing Repository.Discover() on the active file C:\Users\<my_user_name>\source\repos\llvm-project\clang\lib\Format\UnwrappedLineParser.cpp throws in Release mode, but on Debug mode it correctly gets the repository path of C:\Users\<my_user_name>\source\repos\llvm-project\.git\
Reproduction steps
- Create Visual Studio Extension project and add a command, set build to Release mode
- Within the command, get active document with
DTE applicationObject = (DTE)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SDTE)); - Get full file path with
var filePath = applicationObject.ActiveDocument.FullName - Call
var repoPath = Repository.Discover(filePath)
Expected behavior
repoPath holds the path of the repository
Actual behavior
Exception is thrown with the message The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
Version of LibGit2Sharp (release number or SHA1)
0.30.0
Operating system(s) tested; .NET runtime tested
Windows 11, .NET Framework 4.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Release-mode failure from the Visual Studio extension command, using Repository.Discover(filePath) with the active LLVM source file. Inspect the NativeMethods type initializer and compare the Release and Debug behavior on Windows 11 with .NET Framework 4.8. Done means Repository.Discover returns the repository path in the Release build without throwing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100