Daily Usage Issues

"Sequence contains no matching element" exception in Visual Studio Preview

Started by garyp01 on 2,512 views

With Visual Studio Preview (current version: 17.14.0 Preview 6.0) and NCrunch 5.14.0.5, all projects show this error in NCrunch:


System.InvalidOperationException: Sequence contains no matching element
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at nCrunch.Core.BuildManagement.ClientDotNetCoreSdkVersionSelector.OverrideDotNetCoreSdkForProcess(DotNetCoreSdkVersion dotNetCoreSdkVersion, ProcessLoadParameters parameters, IDEVersion vsVersion)
at nCrunch.Core.BuildManagement.BuildProcessLauncher.(EffectiveProcessorArchitecture , BuildSystemParameters , IList`1 , FilePath , DotNetCoreSdkVersion )
at nCrunch.Core.BuildManagement.BuildProcessLauncher..()
at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , EffectiveProcessorArchitecture , GridClientId , BuildSystemParameters , IList`1 , Nullable`1 , GridClientDescription , DotNetCoreSdkVersion  )
at nCrunch.Core.BuildManagement.BuildProcessLauncher.AnalyseComponentBuildInExternalProcess(ComponentLoadParameters parameters, IList`1 customEnvironmentVariables)
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.(EffectiveProcessorArchitecture , String )
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.CreateComponentFromXml(FilePath projectFilePath, ParsedBuildXml projectXml, FilePath solutionFilePath, String[] additionalFilesToIncludeAtSolutionLevel, Boolean isLoadedFromFile, IDEVersion ideVersion, BuildEngineId buildEngineId, ComponentUniqueName componentName, TaskSettings componentTaskSettings, Exception parseException, String targetFrameworkForMsbuild, String visibleTargetFramework)


17.14.0 Preview 6.0 comes with .NET SDK 9.0.300-preview.0.25177.5.

I appreciate that you may not support preview versions, but this used to work and I've seen this error for the last few preview releases, so thought it worth raising in case the same problem may affect the release branch at some point.

Do you know what might be causing this?
Hi, thanks for sharing this issue.

I think this is an edge case in the SDK selection, related to the build's 'preview' status (unfortunately this is a thing, we need special handling for when VS is in a preview state, which isn't required when it goes RTM).

Could you confirm if you have any non preview SDKs installed on your machine? Or whether adjusting the 'Build SDK' NCrunch configuration setting makes any difference?
Thanks for the prompt reply.

Querying 'dotnet sdk check' advises that I only have the 9.0.300-preview.0.25177.5 SDK installed, along with several runtime versions.

Setting the 'Build SDK' setting to '9.0.300-preview.0.25177.5' or any other setting, such as 'VS2022', causes NCrunch to re-initialise but then to fail with the same exception as above.
Thanks for confirming this. I've implemented a fix for this that will be out with the next build. It should be possible to work around this using environment variables.

Under your global NCrunch configuration, find the setting 'Custom environment variables'.

You need to enter two variables into this setting:
DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR = C:\Program Files\dotnet\sdk\9.0.300-preview.0.25177.5\Sdks
DOTNET_MSBUILD_SDK_RESOLVER_SDKS_VER = 9.0.300-preview.0.25177.5

Adjust the paths as necessary if I've guessed your install directory incorrectly.

This should force the resolver to use a specific SDK.
That did the trick - thank you! I look forward to the permanent fix.

Post a reply

Log in to reply.