question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetBuildVersion fails with NullReferenceException when git clone depth is 1

See original GitHub issue

For reproduction purpose consider this commit: https://github.com/c80k/capnproto-dotnetcore/commit/5208531ef2f2abc3612e9116449c702f25dd370e which seems to fix the problem.

Background: The project is built inside an AppVeyor CI. Without the former commit, you’ll see something like this in the log:

C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly. [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.Proxy.git_commit_tree_id(ObjectHandle obj) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Commit.<>c__DisplayClass11_0.<.ctor>b__0(ObjectHandle obj) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.GitObjectLazyGroup.<>c__DisplayClass3_0`1.<Singleton>b__0() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Lazy`1.CreateValue() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Lazy`1.LazyInitValue() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Lazy`1.get_Value() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.LazyGroup`1.LazyWrapper`1.LibGit2Sharp.Core.ILazy<TType>.get_Value() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Commit.get_Tree() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionFile.GetVersion(Commit commit, String repoRelativeProjectDirectory) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.CommitMatchesVersion(Commit commit, SemanticVersion expectedVersion, Position comparisonPrecision, String repoRelativeProjectDirectory) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.<>c__DisplayClass3_0.<GetVersionHeight>b__0(Commit c) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.<>c__DisplayClass30_0.<GetCommitHeight>b__0(Commit p) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Linq.Enumerable.Max(IEnumerable`1 source) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetHeight(Commit commit, Func`2 continueStepping) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(Commit commit, String repoRelativeProjectDirectory, Version baseVersion) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.CalculateVersionHeight(String relativeRepoProjectDirectory, Commit headCommit, VersionOptions committedVersion, VersionOptions workingVersion) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle..ctor(String projectDirectory, Repository repo, Commit head, ICloudBuild cloudBuild, Nullable`1 overrideVersionHeightOffset, String projectPathRelativeToGitRepoRoot) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at MSBuildExtensionTask.ContextAwareTask.Execute() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
Done Building Project "C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj" (Build target(s)) -- FAILED.

The fix just removes the clone_depth property from appveyor.yml.

I understand that cloning the complete repository (i.e. not limiting the clone depth) is essential for calculating the correct version info. My problem was that I totally forgot about the clone depth restriction being set, and that I had a hard time figuring out that this was the actual cause. A meaningful error message instead of letting GetBuildVersion fail unexpectedly would be nice. 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

13reactions
lbotinellycommented, Mar 13, 2020

Just a +1 - experienced a similar issue with actions/checkout@v2 with default parameters. For reference, this was the fix:

      - name: Checkout source
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
3reactions
wh1t3cAt1kcommented, Aug 4, 2020

Just a +1 - experienced a similar issue with actions/checkout@v2 with default parameters. For reference, this was the fix:

      - name: Checkout source
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

Just to note, setting fetch-depth: 0 will fetch the full git history during CI, which, for large repositories, can take quite some time.

If you change your minor version at least sometimes, then setting this to a reasonable restricted value, like 100 or 1000 (depending on your minor versioning frequency), will also work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Checkout to branch when git clone --depth 1 doesn't work
I am running the above mentioned script, but getting the error: "Cloning into 'ndn-cxx'... /source/ndn-cxx /source fatal: Cannot update paths ...
Read more >
How and when to perform a git clone depth 1 example
After a git clone depth 1 operation, attempts to checkout an alternate branch will trigger a pathspec error.
Read more >
Get up to speed with partial clone and shallow clone
git clone --depth=1 <url> creates a shallow clone. These clones truncate the commit history to reduce the clone size. This creates some ...
Read more >
Clone depth not applying for pull request pipelines
Configuring a clone depth in pipelines does not take effect for pull request pipelines. ... If the merge fails, the pipeline will also...
Read more >
Git - git-clone Documentation
Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -- ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found