Sdk: dotnet tool update - error: Sequence contains more than one matching element

Created on 29 Oct 2019  路  9Comments  路  Source: dotnet/sdk

Trying to run:
dotnet tool update --global

Works perfectly running locally, but when run on our build servers (self hosted pool) in Azure DevOps, we sometimes get this error:

Sequence contains more than one matching element
at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Microsoft.DotNet.ToolPackage.ToolPackageInstance.FindLibraryInLockFile(LockFile lockFile, PackageId id)

Same error when using:
dotnet tool install

Any idea what is causing this exception? - can't debug and the error message is really not that helpful.

Most helpful comment

I found out that the problem was due to having a variable: RuntimeIdentifier in my yaml file caused this to blow up, changing my variable name the problem did go away.

So maybe build agents sets environment variables that blow up dotnet tools install.

All 9 comments

Another observation. On the build servers where the update/install fails, the following command:
dotnet tool list -g
also returns the error:
System.InvalidOperationException: Sequence contains more than one matching element

Fixed by manually cleaning folder:
C:\Users\.dotnet\tools

@wli3 can you take a look?

The error now re-appeared on our build servers. The manual deleting of folder:
C:\Users\.dotnet\tools
no longer works, and the command now again gives errors, when run through pipeline.

I am running into the same problem now that my hosted build agent fails on dotnet tool install

Starting: Install dotnetwarp
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.164.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
dotnet tool install -g dotnet-warp
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "d:\a\_temp\d80bb172-7740-4e43-aa9c-f3c3b03e0372.cmd""


SDK Version: 3.1.201

Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what's new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app
--------------------------------------------------------------------------------------
System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.DotNet.ToolPackage.ToolPackageInstance.FindLibraryInLockFile(LockFile lockFile, PackageId id)
   at Microsoft.DotNet.ToolPackage.ToolPackageInstance.GetCommands()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Microsoft.DotNet.ToolPackage.ToolPackageInstance.get_Commands()
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallCommand.Execute()
   at Microsoft.DotNet.Cli.DotNetTopLevelCommandBase.RunCommand(String[] args)
   at Microsoft.DotNet.Tools.Tool.ToolCommand.Run(String[] args)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

@xthsr @livarcocc I think the title of this issue should be changed to better scope the list -g exception being thrown with more than one matching element.


@pksorensen in your scenario, does dotnet tool list -g throw the exception as well?

In regards to install \ update without list -g exception, you could probably attempt workarounds by specifying tool-path, configFile, tool-manifest?

I found out that the problem was due to having a variable: RuntimeIdentifier in my yaml file caused this to blow up, changing my variable name the problem did go away.

So maybe build agents sets environment variables that blow up dotnet tools install.

I am not sure if this is still an issue or not. The issues still exists if i install the tool globally and call dotnet dotnet-warp .

But I was able to get it working in Azure Devopsmpipeline by just calling dotnet-warp "<project file>" instead of dotnet dotnet-warp "<project file>"

The sample yaml is as below

dotnet tool update dotnet-warp --global
dotnet-warp "$(Build.SourcesDirectory)\Dhrutara.DotnetWarp\Dhrutara.DotnetWarp.csproj" --output "$(deployFolder)\Dhrutara.DotnetWarp.exe"

My sample code is here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davkean picture davkean  路  3Comments

srivatsn picture srivatsn  路  3Comments

natemcmaster picture natemcmaster  路  3Comments

noelitoa picture noelitoa  路  3Comments

clairernovotny picture clairernovotny  路  3Comments