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.
Stack Trace:
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
at MyTests.ApiClient.TheClientBuilder.Build()
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 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?
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.