SonarLint Failed To Analyse / Invalid Cast Exception

Please provide

  • Operating system: Windows 11 24H2 (26100.2314)
  • Visual Studio version: VS2022 (17.12.1)
  • SonarLint plugin version: (8.6.0.10679)
  • Programming language you’re coding in: VB.NET, .Net Framework 4.8.1
  • Is connected mode used: Yes, connected to SonarQube Community Edition 10.7

And a thorough description of the problem / question:

On saving files, I see an alert that says Solarlint failed to analyse and to review the output window. On review of the output window, the following error appears.

[SLCoreAnalyzer] Analyzing ClassFunctionsGlobal.vb with id 
[SLCoreAnalyzer] Failed to analyze ClassFunctionsGlobal.vb with id : StreamJsonRpc.RemoteInvocationException: Specified cast is not valid.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SonarLint.VisualStudio.SLCore.Analysis.SLCoreAnalyzer.<ExecuteAnalysisInternalAsync>d__7.MoveNext()
RPC server exception:
System.InvalidCastException: Specified cast is not valid.
      at SonarLint.VisualStudio.Integration.SolutionWorkspaceService.FirstChild(IVsHierarchy hierarchy, VSITEMID rootID)
      at SonarLint.VisualStudio.Integration.SolutionWorkspaceService.ChildrenOf(IVsHierarchy hierarchy, VSITEMID rootID)
      at SonarLint.VisualStudio.Integration.SolutionWorkspaceService.ChildrenOf(IVsHierarchy hierarchy, VSITEMID rootID)
      at SonarLint.VisualStudio.Integration.SolutionWorkspaceService.AllItemsInProject(IVsProject project)
      at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
      at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
      at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
      at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
      at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source, IEqualityComparer`1 comparer)
      at SonarLint.VisualStudio.Integration.SolutionWorkspaceService.<>c__DisplayClass7_0.<GetAllFilesInSolution>b__0()
      at SonarLint.VisualStudio.Infrastructure.VS.ThreadHandling.<>c__DisplayClass5_0.<<RunOnUIThread>b__0>d.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
      at SonarLint.VisualStudio.Infrastructure.VS.ThreadHandling.RunOnUIThread(Action op)
      at SonarLint.VisualStudio.Integration.SolutionWorkspaceService.GetAllFilesInSolution(IVsSolution solution)
      at SonarLint.VisualStudio.SLCore.Listeners.Implementation.ListFilesListener.ListFilesAsync(ListFilesParams parameters)

Appreciate the assistance in fixing this issue and getting better analysis integrated :slight_smile:

Cheers,
Ray

Hi. This should not affect the C#&VB.Net analysis. However, the other languages are affected.

The issue is we get some unexpected response from the VSSDK API. Not sure what it is at the moment. If you could make a reproducer repo it would be great.

In the meantime, we’ll try to ship a mitigation for the problem with our next release, which should happen soon.

Hi Georgii,

Thanks for the reply. Let me know what I can do to help. It appears every time I simply save a file in the output log and the status bar.

Analysis I am using the Sonar Scanner for .NET externally (unless there’s a better way) which then gets “imported” into SonarQube so I can see my errors there.

Looking forward to your updated release that hopefully fixes the issue.

Cheers,
Ray

Yes, the problem is that we need to enumerate the full list of files in the solution, in order for the analysis to work for some of our supported languages (secrets, javascript, etc) and it’s not clear which file/project causes the issue with out integration with VS project system services.

The analysis of C# & VB.Net within ViualStudio works through a different integration and should not be affected, meaning the issues for you VB.Net files will still appear in the IDE.

The Scanner for .NET is used with our server/cloud products and is not related to the IDE, which is why you have no issue with it.

1 Like

We also just released a new version of the extension where we tried to mitigate the problem. The version is 8.8.0.11108 and it should be available via the update in the VS extension manager

Great - let me update my IDE now and see if there’s any change :slight_smile:

By the way, the VS Extension Manager gave me version 8.7.0.11108, not 8.8.

@georgii.borovinskikh looks like the updated version has fixed it. I made a change and saved the file and it immediately analysed it. Here’s the output log, but it seems to be OK now. I also noticed the update from SonarLint to SonarQube for Visual Studio as the extension and item in the output window dropdown.


> Initializing the telemetry package...
> Finished initializing the telemetry package...
> Initializing the daemon package...
> [Connection Migration] Connections.json exists. Migrating connections from existing bindings was not performed
> Connecting to 'https://<URL_HIDDEN>/'.
> [SLCoreHandler] Creating SLCore instance
> [SLCoreHandler] Starting SLCore instance
> Loaded settings from "\AppData\Roaming\SonarLint for Visual Studio\settings.json".
> Current VS version:
>     Visual Studio Professional 2022
>     17.12.35514.174
>     17.12.1
> [NodeJSLocator] Checking environment variable SONAR_NODEJS_PATH
> [NodeJsLocator] Environment variable is not set
> Finished initializing the daemon package.
> Initializing the SonarQube for Visual Studio package...
> Finishing initializing the SonarQube for Visual Studio package
> Initializing the notifications package...
> Not connected: not checking for notifications
> Finished initializing the notifications package
> [SharedBindingConfigProvider] The .sonarlint shared folder was not found
> [SLCORE] Can't open directory channel. Log directory fsync won't be performed.
> Connected to SonarQube '10.7.0.96327'.
> [SLCORE] Node.js could not be automatically detected, has to be configured manually in the SonarLint preferences!
> Updated analysis readiness: True
> Binding has changed. Open documents will be re-analysed.
> Connected: checking for notifications
> [ConnectedMode] Initializing package...
> [ConnectedMode] Package initialized
> [Hotspots] Fetching all hotspots...
> [Suppressions] Fetching all suppressions...
> [Taint] Initializing taint issues synchronization package...
> Updated analysis readiness: True
> Starting job: "re-analyzing 0 document(s)...". Time: 4:20:18 PM
> Finished job "re-analyzing 0 document(s)..." started at 4:20:18 PM. Elapsed time: 8ms
> [ConnectedMode/BranchMapping] Matching Sonar server branch: master
> [ConnectedMode/BranchMapping] Closest Sonar server branch: master
> [ConnectedMode/BranchMapping] Matching Sonar server branch: master
> [ConnectedMode/BranchMapping] Closest Sonar server branch: master
> [ConnectedMode/BranchMapping] Matching Sonar server branch: master
> [ConnectedMode/BranchMapping] Closest Sonar server branch: master
> [Hotspots] Finished fetching all hotspots
> [Taint] Fetched 0 taint vulnerabilities.
> [Taint] Finished initializing taint issues synchronization package.
> [ConnectedMode/BranchMapping] Closest Sonar server branch: master
> [SLCoreAnalyzer] Analyzing file.vb with id 
> [SLCoreAnalyzer] Finished analyzing file.vb with id 979729f2-101f-47b5-be2c-2a36b99f5e32, analysis time: 0s
> [SLCoreAnalyzer] Found 0 issue(s) for file.vb
> [SLCoreAnalyzer] Finished analyzing file.vb with id 979729f2-101f-47b5-be2c-2a36b99f5e32, analysis time: 0s
> [SLCoreAnalyzer] Found 0 issue(s) for file.vb
> [ConnectedMode/BranchMapping] Matching Sonar server branch: master
> [ConnectedMode/BranchMapping] Closest Sonar server branch: master
> [ServerIssueStore] Raising change event...
> [Suppressions] Finished fetching all suppressions

Thanks so much! :smiley:

1 Like

@UncleRaymondo sorry, yes, the version is 8.7, not 8.8.

Glad that the change removed the error log.

Could you try enabling verbose logs and see if a similar issue still appears in the logs? We’ve moved logging to a lower level as part of the mitigation Troubleshooting - SonarLint Documentation - Visual Studio

Hi @georgii.borovinskikh,

Apologies, I just realised that you had replied and asked for something.

I’ve attached a PII Cleaned Verbose Log for you to peruse.

Let me know if you need anything else.

Cheers,
Ray

SonarLint_Verbose_Log_291124_1857.txt (160.6 KB)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.