GitVersion: [Bug] Object reference not set to an instance of an object.
Describe the bug
Expected Behavior
GitVersion successed
Actual Behavior
GitVersion failed with Object reference not set to an instance of an object.
Possible Fix
Update the code 😃
Steps to Reproduce
Not sure, it happens only on one repo
Context
I’m integrating old repo with GitVersion and I’m getting this error.
Your Environment
Azure DevOps pipeline. Branches structure:
develop
feature/cicd
remotes/origin/HEAD -> origin/develop
remotes/origin/develop
remotes/origin/feat/299392_file_stats
remotes/origin/feature/cicd
remotes/origin/fix/double_header_logs
remotes/origin/fix/log4j_to_2_17v
remotes/origin/master
remotes/origin/release/299392_file_stats
I’m running it from feature/cicd
- 
Version Used: 5.10.3 
- 
Operating System and version (Windows 10, Ubuntu 18.04): Pool: Azure Pipelines Image: ubuntu-latest Downloading task: gitversion/setup (0.9.13) Downloading task: gitversion/execute (0.9.13) 
- 
Link to your project: 
- 
Link to your CI build (if appropriate): 
2022-09-08T13:29:31.3434162Z ##[section]Starting: gitversion/execute
2022-09-08T13:29:31.3444661Z ==============================================================================
2022-09-08T13:29:31.3445051Z Task         : Execute GitVersion Task
2022-09-08T13:29:31.3445415Z Description  : Easy Semantic Versioning (http://semver.org) for projects using Git
2022-09-08T13:29:31.3445720Z Version      : 0.9.13
2022-09-08T13:29:31.3445942Z Author       : GitTools Contributors
2022-09-08T13:29:31.3446269Z Help         : See the [documentation](https://gitversion.net/docs/) for help
2022-09-08T13:29:31.3446674Z ==============================================================================
2022-09-08T13:29:31.5860064Z Command: dotnet-gitversion /home/vsts/work/1/s /output json /output buildserver
2022-09-08T13:29:31.5878920Z [command]/opt/hostedtoolcache/GitVersion.Tool/5.10.3/x64/dotnet-gitversion /home/vsts/work/1/s /output json /output buildserver
2022-09-08T13:29:32.2116264Z   ERROR [09/08/22 13:29:32:13] An unexpected error occurred:
2022-09-08T13:29:32.2117503Z INFO [09/08/22 13:29:31:88] Working directory: /home/vsts/work/1/s
2022-09-08T13:29:32.2125467Z INFO [09/08/22 13:29:31:91] Project root is: /home/vsts/work/1/s/
2022-09-08T13:29:32.2127706Z System.NullReferenceException: Object reference not set to an instance of an object.
2022-09-08T13:29:32.2128445Z INFO [09/08/22 13:29:31:91] DotGit directory is: /home/vsts/work/1/s/.git
2022-09-08T13:29:32.2130174Z    at LibGit2Sharp.Core.Handles.ObjectHandle.op_Implicit(ObjectHandle handle) in /_/LibGit2Sharp/Core/Handles/Objects.cs:line 509
2022-09-08T13:29:32.2130988Z INFO [09/08/22 13:29:31:91] Branch from build environment: refs/heads/feature/cicd
2022-09-08T13:29:32.2132530Z    at LibGit2Sharp.Core.Proxy.git_commit_author(ObjectHandle obj) in /_/LibGit2Sharp/Core/Proxy.cs:line 289
2022-09-08T13:29:32.2134061Z INFO [09/08/22 13:29:31:91] Begin: Normalizing git directory for branch 'refs/heads/feature/cicd'
2022-09-08T13:29:32.2135806Z    at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.LibGit2Sharp.Core.LazyGroup<T>.IEvaluator<TInput>.Evaluate(TInput input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 88
2022-09-08T13:29:32.2137341Z   INFO [09/08/22 13:29:31:95] One remote found (origin -> 'https://dh-platforms-devops@dev.azure.com/dh-platforms-devops/app-axon/_git/app-axon.connectors.remote-oracle').
2022-09-08T13:29:32.2139101Z    at LibGit2Sharp.Core.LazyGroup`1.<Evaluate>b__6_0(T input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 36
2022-09-08T13:29:32.2139948Z   INFO [09/08/22 13:29:31:96] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
2022-09-08T13:29:32.2141661Z    at LibGit2Sharp.Core.GitObjectLazyGroup.EvaluateInternal(Action`1 evaluator) in /_/LibGit2Sharp/Core/GitObjectLazyGroup.cs:line 20
2022-09-08T13:29:32.2142351Z   INFO [09/08/22 13:29:31:96] Creating local branch feature/cicd
2022-09-08T13:29:32.2143781Z    at LibGit2Sharp.Core.LazyGroup`1.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 34
2022-09-08T13:29:32.2145970Z   INFO [09/08/22 13:29:32:00] Creating local branch from remote tracking 'refs/remotes/origin/b4f12db8aff434f911661ab7811620f0b76cb6af'.
2022-09-08T13:29:32.2148431Z    at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 80
2022-09-08T13:29:32.2149704Z   INFO [09/08/22 13:29:32:01] HEAD points at branch 'refs/heads/feature/cicd'.
2022-09-08T13:29:32.2151354Z    at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.get_Value() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 73
2022-09-08T13:29:32.2152296Z   INFO [09/08/22 13:29:32:02] End: Normalizing git directory for branch 'refs/heads/feature/cicd' (Took: 100.98ms)
2022-09-08T13:29:32.2153922Z    at LibGit2Sharp.Commit.get_Committer() in /_/LibGit2Sharp/Commit.cs:line 87
2022-09-08T13:29:32.2154456Z   INFO [09/08/22 13:29:32:03] Begin: Loading version variables from disk cache
2022-09-08T13:29:32.2155420Z    at GitVersion.Commit..ctor(Commit innerCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 17
2022-09-08T13:29:32.2156722Z     INFO [09/08/22 13:29:32:03] Cache file /home/vsts/work/1/s/.git/gitversion_cache/1107BD61A2009AC1E6AABBA65B0246055CCF128E.yml not found.
2022-09-08T13:29:32.2158476Z    at GitVersion.Commit.<>c.<.ctor>b__3_0(Commit parent) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 16
2022-09-08T13:29:32.2159173Z   INFO [09/08/22 13:29:32:03] End: Loading version variables from disk cache (Took: 0.74ms)
2022-09-08T13:29:32.2160561Z    at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
2022-09-08T13:29:32.2161044Z   INFO [09/08/22 13:29:32:03] Using latest commit on specified branch
2022-09-08T13:29:32.2162339Z    at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
2022-09-08T13:29:32.2162876Z   INFO [09/08/22 13:29:32:06] Begin: Attempting to inherit branch configuration from parent branch
2022-09-08T13:29:32.2164887Z    at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 77
2022-09-08T13:29:32.2166088Z   INFO [09/08/22 13:29:32:06] End: Attempting to inherit branch configuration from parent branch (Took: 7.43ms)
2022-09-08T13:29:32.2168153Z    at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
2022-09-08T13:29:32.2169245Z   INFO [09/08/22 13:29:32:13] Attempting to show the current git graph (please include in issue): 
2022-09-08T13:29:32.2171053Z    at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 28
2022-09-08T13:29:32.2172001Z   INFO [09/08/22 13:29:32:13] Showing max of 100 commits
2022-09-08T13:29:32.2173471Z    at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 39
2022-09-08T13:29:32.2174934Z   INFO [09/08/22 13:29:32:18] * b4f12db 63 seconds ago  (grafted, HEAD -> feature/cicd, origin/b4f12db8aff434f911661ab7811620f0b76cb6af, b4f12db8aff434f911661ab7811620f0b76cb6af)
2022-09-08T13:29:32.2176712Z    at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
2022-09-08T13:29:32.2177175Z 
2022-09-08T13:29:32.2178263Z    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
2022-09-08T13:29:32.2178988Z INFO [09/08/22 13:29:31:79] Applicable build agent found: 'AzurePipelines'.
2022-09-08T13:29:32.2180682Z    at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
2022-09-08T13:29:32.2181469Z INFO [09/08/22 13:29:31:88] Working directory: /home/vsts/work/1/s
2022-09-08T13:29:32.2182225Z INFO [09/08/22 13:29:31:91] Project root is: /home/vsts/work/1/s/
2022-09-08T13:29:32.2182806Z    at System.Lazy`1.CreateValue()
2022-09-08T13:29:32.2183360Z INFO [09/08/22 13:29:31:91] DotGit directory is: /home/vsts/work/1/s/.git
2022-09-08T13:29:32.2184052Z INFO [09/08/22 13:29:31:91] Branch from build environment: refs/heads/feature/cicd
2022-09-08T13:29:32.2184628Z    at System.Lazy`1.get_Value()
2022-09-08T13:29:32.2185583Z INFO [09/08/22 13:29:31:91] Begin: Normalizing git directory for branch 'refs/heads/feature/cicd'
2022-09-08T13:29:32.2186598Z    at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
2022-09-08T13:29:32.2188510Z    at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
2022-09-08T13:29:32.2190229Z   INFO [09/08/22 13:29:31:95] One remote found (origin -> 'https://dh-platforms-devops@dev.azure.com/dh-platforms-devops/app-axon/_git/app-axon.connectors.remote-oracle').
2022-09-08T13:29:32.2192043Z    at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
2022-09-08T13:29:32.2192938Z   INFO [09/08/22 13:29:31:96] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
2022-09-08T13:29:32.2194707Z    at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
2022-09-08T13:29:32.2195435Z   INFO [09/08/22 13:29:31:96] Creating local branch feature/cicd
2022-09-08T13:29:32.2196673Z   INFO [09/08/22 13:29:32:00] Creating local branch from remote tracking 'refs/remotes/origin/b4f12db8aff434f911661ab7811620f0b76cb6af'.
2022-09-08T13:29:32.2197678Z   INFO [09/08/22 13:29:32:01] HEAD points at branch 'refs/heads/feature/cicd'.
2022-09-08T13:29:32.2198754Z   INFO [09/08/22 13:29:32:02] End: Normalizing git directory for branch 'refs/heads/feature/cicd' (Took: 100.98ms)
2022-09-08T13:29:32.2199497Z   INFO [09/08/22 13:29:32:03] Begin: Loading version variables from disk cache
2022-09-08T13:29:32.2200293Z     INFO [09/08/22 13:29:32:03] Cache file /home/vsts/work/1/s/.git/gitversion_cache/1107BD61A2009AC1E6AABBA65B0246055CCF128E.yml not found.
2022-09-08T13:29:32.2201121Z   INFO [09/08/22 13:29:32:03] End: Loading version variables from disk cache (Took: 0.74ms)
2022-09-08T13:29:32.2201793Z   INFO [09/08/22 13:29:32:03] Using latest commit on specified branch
2022-09-08T13:29:32.2202768Z   INFO [09/08/22 13:29:32:06] Begin: Attempting to inherit branch configuration from parent branch
2022-09-08T13:29:32.2203560Z   INFO [09/08/22 13:29:32:06] End: Attempting to inherit branch configuration from parent branch (Took: 7.43ms)
2022-09-08T13:29:32.2204723Z   ERROR [09/08/22 13:29:32:13] An unexpected error occurred:
2022-09-08T13:29:32.2205392Z System.NullReferenceException: Object reference not set to an instance of an object.
2022-09-08T13:29:32.2206397Z    at LibGit2Sharp.Core.Handles.ObjectHandle.op_Implicit(ObjectHandle handle) in /_/LibGit2Sharp/Core/Handles/Objects.cs:line 509
2022-09-08T13:29:32.2207264Z    at LibGit2Sharp.Core.Proxy.git_commit_author(ObjectHandle obj) in /_/LibGit2Sharp/Core/Proxy.cs:line 289
2022-09-08T13:29:32.2208190Z    at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.LibGit2Sharp.Core.LazyGroup<T>.IEvaluator<TInput>.Evaluate(TInput input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 88
2022-09-08T13:29:32.2209111Z    at LibGit2Sharp.Core.LazyGroup`1.<Evaluate>b__6_0(T input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 36
2022-09-08T13:29:32.2209959Z    at LibGit2Sharp.Core.GitObjectLazyGroup.EvaluateInternal(Action`1 evaluator) in /_/LibGit2Sharp/Core/GitObjectLazyGroup.cs:line 20
2022-09-08T13:29:32.2210975Z    at LibGit2Sharp.Core.LazyGroup`1.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 34
2022-09-08T13:29:32.2211812Z    at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 80
2022-09-08T13:29:32.2212596Z    at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.get_Value() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 73
2022-09-08T13:29:32.2213314Z    at LibGit2Sharp.Commit.get_Committer() in /_/LibGit2Sharp/Commit.cs:line 87
2022-09-08T13:29:32.2214105Z    at GitVersion.Commit..ctor(Commit innerCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 17
2022-09-08T13:29:32.2215033Z    at GitVersion.Commit.<>c.<.ctor>b__3_0(Commit parent) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 16
2022-09-08T13:29:32.2215956Z    at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
2022-09-08T13:29:32.2216623Z    at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
2022-09-08T13:29:32.2217836Z    at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 77
2022-09-08T13:29:32.2219631Z    at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
2022-09-08T13:29:32.2230583Z    at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 28
2022-09-08T13:29:32.2232457Z    at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 39
2022-09-08T13:29:32.2233603Z    at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
2022-09-08T13:29:32.2234452Z    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
2022-09-08T13:29:32.2235133Z    at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
2022-09-08T13:29:32.2235776Z    at System.Lazy`1.CreateValue()
2022-09-08T13:29:32.2236238Z    at System.Lazy`1.get_Value()
2022-09-08T13:29:32.2237038Z    at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
2022-09-08T13:29:32.2238214Z    at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
2022-09-08T13:29:32.2239366Z    at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
2022-09-08T13:29:32.2241270Z    at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
2022-09-08T13:29:32.2242074Z   INFO [09/08/22 13:29:32:13] Attempting to show the current git graph (please include in issue): 
2022-09-08T13:29:32.2242580Z   INFO [09/08/22 13:29:32:13] Showing max of 100 commits
2022-09-08T13:29:32.2243928Z   INFO [09/08/22 13:29:32:18] * b4f12db 63 seconds ago  (grafted, HEAD -> feature/cicd, origin/b4f12db8aff434f911661ab7811620f0b76cb6af, b4f12db8aff434f911661ab7811620f0b76cb6af)
2022-09-08T13:29:32.2244620Z 
2022-09-08T13:29:32.2244924Z   INFO [09/08/22 13:29:32:20] Done writing 
2022-09-08T13:29:32.2283238Z ##[error]SyntaxError: Unexpected end of JSON input
2022-09-08T13:29:32.2302098Z ##[section]Finishing: gitversion/execute
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 17 (5 by maintainers)
In YAML based pipelines, this fixed it for me.
It is a pipeline setting. The screenshots at https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/pipeline-options-for-git?view=azure-devops&tabs=yaml#azure-pipelines-azure-devops-server-2019-and-newer show you how to get to the setting. It is talking about the “Clean” setting but scrolling to the bottom of that page should have the “Shallow fetch” setting.
@asbjornu: Can we add a simple check like #3479?
@mpalmujoki thank you! With
fetchDepth: 0is enough, and will overwrite the setting in the pipeline settings UI.Official documentation:
Thank you @sandejd1 I found it. Looks like @tannerwatson said, some default options have been changed, this was pipeline that I created two days ago.