Server version: SonarQube Enterprise Edition Version 9.7.1 (build 62043)
Client version: dotnet-sonarscanner 5.11.0
.NET version: .NET 6.0
When running tests that use or reference a Refit client (using Refit 6.3.2) using
dotnet test after running
dotnet sonarscanner begin, the tests throw an exception similar to the following:
System.InvalidOperationException : IRefitClient doesn't look like a Refit interface. Make sure it has at least one method with a Refit HTTP method attribute and Refit is installed in the project.
at Refit.RestService.GetGeneratedType(Type refitInterfaceType) in /_/Refit/RestService.cs:line 173
at Refit.RestService.For(Type refitInterfaceType, HttpClient client, IRequestBuilder builder) in /_/Refit/RestService.cs:line 76
at Refit.RestService.For[T](HttpClient client, IRequestBuilder`1 builder) in /_/Refit/RestService.cs:line 20
at Refit.RestService.For[T](HttpClient client, RefitSettings settings) in /_/Refit/RestService.cs:line 34
at Refit.RestService.For[T](String hostUrl, RefitSettings settings) in /_/Refit/RestService.cs:line 54
Without Sonar scanner in play, the tests work correctly.
Refit uses source generators to generate the implementation of the API interfaces, and it appears that Sonar scanner is interfering with the code generation.
There’s a similar bug report here without an obvious conclusion, and a Refit issue here which clarifies that the issue is not with the Refit library.
I am unable to reproduce the issue, would it be possible to provide us with a minimal reproducer project?
All the best,
Here’s a sample that would reproduce the issue (it might need to be updated to .NET 6): refit/samples at main · reactiveui/refit · GitHub
I have done an analysis of the Meow.sln you suggested both while targeting .NET5 and 6 and it does not fail for me. Did it fail for you or you just suggested it as a reproducer without trying it on your side?
I managed to come up with a scenario when the build fails. To check if it is the same scenario that you have, can you tell me what is the value of the
sonar.dotnet.excludeTestProjects parameter for your analysis?
All the best,
We use the following parameter:
Could you please try setting the parameter to
false? That should be a workaround for the problem you are having. And if it indeed does fix it as I believe it will, I will open an issue for the scanner for dotnet to fix the problem.
I have created the following issue, where you can track the progress.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.