Unable to run sonarlint on C++ Visual studio

Please provide

  • Operating system: Windows 10
  • Visual Studio version: 2022 Community Edition
  • SonarLint plugin version:
  • Programming language you’re coding in: C++
  • Is connected mode used: no
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:
I am currently working to configure sonarlint for a C++ project. I have installed the SonarLint extension from Visual Studio. When I open a .cpp file I am getting below errors.

We are using MakeFile in Configuration type and platform toolset being used is v140.

[ThreadId 1] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 1] 	Could not get the file configuration
[ThreadId 1] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 1] 	Could not get the file configuration
[ThreadId 48] [DEBUG] [ExclusionSettingsStorage] Standalone mode, exclusions are not supported.
[ThreadId 48] [DEBUG] [AnalyzableFileIndicator] No server settings were found.
[ThreadId 48] [SecretsAnalyzer] Analyzing C:\Git_repos\test\cpp\test.cpp
[ThreadId 25] [DEBUG] [CompilationDatabaseLocator] Could not find project root directory
[ThreadId 23] [DEBUG] [CompilationDatabaseLocator] Could not find project root directory
[ThreadId 48] [SecretsAnalyzer] Finished analyzing C:\Git_repos\test\test.cpp, analysis time: 0.058s
[ThreadId 48] [SecretsAnalyzer] Found 0 issue(s) for C:\Git_repos\test\test.cpp
[ThreadId 48] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 48] Trying to create request for C:\Git_repos\test\test.cpp
[ThreadId 1] [CFamily Analysis] Error retrieving VCX configuration. File: C:\Git_repos\test\test.cpp, Error: System.ArgumentException: Unsupported StructMemberAlignment: 1Byte
Parameter name: value
   at SonarLint.VisualStudio.Integration.Vsix.CFamily.VcxProject.CmdBuilder.ConvertStructMemberAlignment(String value)
   at SonarLint.VisualStudio.Integration.Vsix.CFamily.VcxProject.CmdBuilder.AddOptFromProperties(IVCRulePropertyStorage properties)
   at SonarLint.VisualStudio.Integration.Vsix.CFamily.VcxProject.FileConfig.TryGet(ILogger logger, ProjectItem dteProjectItem, String absoluteFilePath)
   at SonarLint.VisualStudio.Integration.Vsix.CFamily.VcxProject.FileConfigProvider.Get(ProjectItem projectItem, String analyzedFilePath, CFamilyAnalyzerOptions analyzerOptions)
[ThreadId 1] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 1] 	Could not get the file configuration
[ThreadId 86] [DEBUG] [CompilationDatabaseLocator] Could not find project root directory
[ThreadId 86] Unable to retrieve the configuration for file 'C:\Git_repos\test\test.cpp'.
    Check the file is part of a supported project type in the current solution.

Since there was an error related to CompilationDatabaseLocator, I have generated compile_commands.json file and tried to use it in settings. I am still getting the same error.

Hey there.

SonarLint is expecting 1Bytes instead of 1Byte as the StructMemberAlignment.

And I don’t have a clue if your config is valid and we made a copy-paste error… or if your config is invalid. So I’m going to flag an expert :slight_smile:

1 Like

Hi Colin,

With empty settings.json file, I can see sonarlint errors for C# projects in Visual Studio. but the problem here is specifically with C++ project/solution.

Hi @sandilya1599 the change suggested by Colin was related to C++, not C#. Our VisualStudio integration is written in C#, hence why the link to a C# file.

Unfortunately though, we don’t currently support Makefile project analysis in SonarLint for VisualStudio. You can still try the suggested fix, as it seems to be a minor change (and it would work for a non-Makefile project), but most likely the analysis will still not work.

I will forward the feedback regarding the Makefile support to our PMs.