petercli
(Peter Clisby)
June 2, 2023, 10:18am
2
Note that it seems a similar error to that described in the following issue which my reading of suggests there were multiple profiles for C# (one for .Net Core the other for .Net Framework) but that doesn’t seem to be the case for us unless mistaken
opened 07:41AM - 16 Nov 20 UTC
closed 03:56PM - 26 Feb 21 UTC
Type: Bug
### Description
Last week someone in our organization installed the C# Sonar … .NET Core way in addition to the C# Sonar way we already had installed. Since then we started consistently getting the following exception in the Prepare Analysis Configuration Azure DevOps task.
>Failed to request and parse 'http://.../api/qualityprofiles/search?project=...': Sequence contains more than one matching element
With the following (partial) stacktrace:
```
##[error]Unhandled Exception:
##[error]System.InvalidOperationException: Sequence contains more than one matching element
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at SonarScanner.MSBuild.PreProcessor.SonarWebService.<>c__DisplayClass6_0.<<TryGetQualityProfile>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
```
The request for quality profiles includes the following two profiles:
```json
{
"profiles": [
{
"key": "cs-sonar-way-16701",
"name": "Sonar way",
"language": "cs",
"languageName": "C#",
"isInherited": false,
"isDefault": true,
"activeRuleCount": 143,
"activeDeprecatedRuleCount": 0,
"rulesUpdatedAt": "2017-06-23T08:34:07+0000",
"lastUsed": "2020-11-10T17:48:00+0100",
"userUpdatedAt": "2017-06-23T10:34:07+0200"
},
{
"key": "cs-sonar-way-net-core-23051",
"name": "Sonar way .NET Core",
"language": "cs",
"languageName": "C#",
"isInherited": false,
"isDefault": false,
"activeRuleCount": 142,
"activeDeprecatedRuleCount": 0,
"projectCount": 1,
"rulesUpdatedAt": "2020-08-03T13:16:55+0000",
"lastUsed": "2020-11-04T16:07:44+0100",
"userUpdatedAt": "2020-08-03T15:16:55+0200"
}
]
}
```
The C# Sonar .NET Core way is only assigned to a single project which is not one we are analyzing so we expected it to just use the default C# profile which is the one which was already installed.
### Repro steps
Please provide the steps required to reproduce the problem
1. Install two profiles for C#.
2. Run the Prepare Analysis Configuration Azure DevOps task on a C# project.
### Expected behavior
Sonar scanner uses the profile which is assigned to that project or the default one.
### Actual behavior
Sonar scanner throws an InvalidOperationException.
### Known workarounds
None.
### Related information
* SonarScanner for MSBuild version: 5.0.4
* SonarQube server version: 6.3.1
* Languages in your solution: C#
* Azure DevOps task version: 4.17.0