使用az artifacts universal publish发布通用包时触发NullReferenceException异常
之前的讨论中,我被建议用Universal Packages在Azure DevOps内部发布工具。但发布单个可执行文件时,触发了冗长的空引用异常,无法判断是操作问题还是软件Bug。
执行的命令:
az artifacts universal publish --organization https://dev.azure.com/Myorg --feed MyFeed --name MyPackageName --version 0.0.1 --path mytool.exe --description TestDescription --scope project --project ProjectName
运行后显示- Publishing ..,几秒后报错:
Failed to hash a page of files. Exception listed below...
An exception was thrown: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.Services.BlobStore.WebApi.DedupManifestArtifactClient.<>c__DisplayClass26_0.b__11(FileBlobDescriptor file)
at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.<>c__DisplayClass31_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.VisualStudio.Services.Content.Common.NonSwallowingActionBlock.<>c__DisplayClass5_01.<<CreateNonSwallowingFunc>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.PaginateAndProcessFilesHelperAsync(String sourceDirectory, Boolean shouldPreserveSymbolicLink, Boolean shouldPreservePermissionValue, IEnumerable1 pathsInDir, Action1 hashCompleteCallback, HashType hashType, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.<>c__DisplayClass26_0.<<PaginateAndProcessFiles>b__0>d.MoveNext() Encountered an unexpected error. System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.VisualStudio.Services.BlobStore.WebApi.DedupManifestArtifactClient.<>c__DisplayClass26_0.<PublishAsync>b__11(FileBlobDescriptor file) at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.<>c__DisplayClass31_0.<<PaginateAndProcessFilesHelperAsync>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.VisualStudio.Services.Content.Common.NonSwallowingActionBlock.<>c__DisplayClass5_01.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.PaginateAndProcessFilesHelperAsync(String sourceDirectory, Boolean shouldPreserveSymbolicLink, Boolean shouldPreservePermissionValue, IEnumerable1 pathsInDir, Action1 hashCompleteCallback, HashType hashType, CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.<>c__DisplayClass26_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.VisualStudio.Services.Content.Common.ExceptionExtensions.ReThrow(Exception ex)
at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.<>c__DisplayClass26_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.VisualStudio.Services.Content.Common.NonSwallowingActionBlock.<>c__DisplayClass5_01.<<CreateNonSwallowingFunc>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.VisualStudio.Services.BlobStore.Common.PrecomputedHashesGenerator.PaginateAndProcessFiles(String sourceDirectory, HashType hashType, IEnumerable1 pages, Boolean shouldPreserveSymbolicLink, Boolean shouldPreservePermissionValue, CancellationToken cancellationToken, Action1 hashCompleteCallback) at Microsoft.VisualStudio.Services.BlobStore.WebApi.DedupManifestArtifactClient.PublishAsync(String sourceDirectory, IReadOnlyCollection1 fileInfoList, IReadOnlyDictionary2 otherFiles, ArtifactPublishOptions artifactPublishOptions, String manifestFileOutputPath, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Packaging.UPackClientShared.UPackSharedClient.PushWithoutCheckingForDuplicatePackageAsync(String projectNameOrId, String feedNameOrId, String packageName, String packageVersion, String description, String sourceDirectory, Boolean honorIgnoreOptions, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Packaging.UPackClientShared.UPackSharedClient.PushAsync(String projectNameOrId, String feedNameOrId, String packageName, String packageVersion, String description, String sourceDirectory, Boolean honorIgnoreOptions, CancellationToken cancellationToken) at ArtifactTool.Commands.UPackPublishCommand.<>c__DisplayClass25_0.<<ExecuteAsync>b__0>d.MoveNext() in D:\a\1\s\src\ArtifactTool\Commands\UPack\UPackPublishCommand.cs:line 59 --- End of stack trace from previous location --- at ArtifactTool.Commands.UPack.UPackExceptionMapper.WithExceptionHandlingAsync(Func1 act) in D:\a\1\s\src\ArtifactTool\Commands\UPack\UPackExceptionMapper.cs:line 39
at ArtifactTool.Commands.UPackPublishCommand.ExecuteAsync() in D:\a\1\s\src\ArtifactTool\Commands\UPack\UPackPublishCommand.cs:line 57
at ArtifactTool.Commands.CommandBase.OnExecuteAsync() in D:\a\1\s\src\ArtifactTool\Commands\CommandBase.cs:line 105
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.InvokeAsync(MethodInfo method, Object instance, Object[] arguments) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 77
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 62
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<b__0>d.MoveNext() in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 25
--- End of stack trace from previous location ---
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass126_0.b__0() in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 505
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 611
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 57
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 145
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](IConsole console, String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 130
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 112
Process ['C:\Users\RobertoBasile.azure\azuredevops\cli\tools\artifacttool\ArtifactTool_win10-x64_0.2.308\artifacttool', 'universal', 'publish', '--service', 'https://dev.azure.com/MyOrg', '--patvar', 'AZURE_DEVOPS_EXT_ARTIFACTTOOL_PATVAR', '--feed', 'MyFeed', '--package-name', 'mytool', '--package-version', '0.0.1', '--path', 'mytool.exe', '--project', 'ProjectName', '--description', 'TestDescription'] with PID 40472 exited with return code 1
请问这是什么原因导致的?
这个空引用异常的核心原因是直接指定单个文件作为--path参数值,Azure DevOps的Universal Packages发布命令预期--path指向目录而非单个文件,处理单个文件时存在逻辑缺陷。
解决步骤:
- 创建临时目录,将
mytool.exe移入该目录 - 修改发布命令,将
--path指向这个目录:
az artifacts universal publish --organization https://dev.azure.com/Myorg --feed MyFeed --name MyPackageName --version 0.0.1 --path ./temp-dir --description TestDescription --scope project --project ProjectName
修改后命令可正常完成哈希计算与发布流程,不再触发空引用异常。另外也可尝试更新artifacttool到最新版本,但优先推荐目录方式,这是命令设计的预期使用方式。
内容的提问来源于stack exchange,提问作者ff8mania

