AD0001 errors: System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG

Please provide

  • Operating system: Windows 10 Pro 21H2
  • SonarLint plugin version: 6.8.0.53188
  • Language you’re coding in: C#
  • Is connected mode used: No:
  • Visual Studio 2022 17.4.0 Preview 1

Building the solution I’m working on results in over 150,000 AD0001 warnings that all include the below exception (albeit with slightly different call stacks).
I am seeing some Sonar Lint warnings produced, so it’s not as if it’s totally broken!
I’ve uninstalled/reinstalled SonarLint and the issue remains.
Any suggestions?

System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.ServiceHub.HostLib.ServiceLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at SonarAnalyzer.Rules.CSharp.FieldShouldBeReadonly.ReadonlyFieldCollector.PartialTypeDeclarationProcessor.TupleExpressionsOrSelf(ExpressionSyntax expression)
   at SonarAnalyzer.Rules.CSharp.FieldShouldBeReadonly.ReadonlyFieldCollector.PartialTypeDeclarationProcessor.CollectFieldsFromAssignments()
   at SonarAnalyzer.Rules.CSharp.FieldShouldBeReadonly.ReadonlyFieldCollector.PartialTypeDeclarationProcessor.CollectFields()
   at SonarAnalyzer.Rules.CSharp.FieldShouldBeReadonly.ReadonlyFieldCollector..ctor(IEnumerable`1 partialTypeDeclarations)
   at SonarAnalyzer.Rules.CSharp.FieldShouldBeReadonly.<>c.<Initialize>b__9_0(SymbolAnalysisContext c)
   at SonarAnalyzer.Helpers.SonarAnalysisContext.<>c__DisplayClass47_0`1.<RegisterContextAction>b__0(TContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolActionsCore>b__50_1(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.ServiceHub.HostLib.ServiceLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
-----
System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.ServiceHub.HostLib.ServiceLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

The issue has gone away after the update to Visual Studio Version 17.4.0 Preview 2.0 :slight_smile:

2 Likes

I still have this issue using final version of Visual Studio 2022 17.4

  • Operating system: Windows 11 Pro 21H2 (Build 22000.1165)
  • SonarLint plugin version: 6.9.0.54300
  • Language you’re coding in: C#
  • Is connected mode used: No:
  • Visual Studio 2022 17.4.0

I’m only using the visual studio extension, not any nuget package. But I see that in the nuget package the version is 8.48 and the error is for version 8.44. Maybe an update in the extension is needed?

My error is pretty similar:

Severity	Code	Description	Project	File	Line	Suppression State
Error	AD0001	Analyzer 'SonarAnalyzer.Rules.CSharp.AbstractTypesShouldNotHaveConstructors' threw an exception of type 'System.IO.FileNotFoundException' with message 'Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.'.
Exception occurred with following context:
Compilation: (project name here)
SyntaxTree: C:\Projects\(project page)\file.cs
SyntaxNode: public RequestLogFilterAttribute ... [ConstructorDeclarationSyntax]@[781..1072) (22,8)-(29,9)

System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.ServiceHub.HostLib.ServiceLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at SonarAnalyzer.Rules.CSharp.AbstractTypesShouldNotHaveConstructors.GetModifiers(SyntaxNode node)
   at SonarAnalyzer.Rules.CSharp.AbstractTypesShouldNotHaveConstructors.<>c.<Initialize>b__6_0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.DiagnosticAnalyzerContextHelper.<>c__DisplayClass1_0`1.<RegisterSyntaxNodeActionInNonGenerated>b__0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.SonarAnalysisContext.<>c__DisplayClass47_0`1.<RegisterContextAction>b__0(TContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__62`1.<ExecuteSyntaxNodeAction>b__62_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.ServiceHub.HostLib.ServiceLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
-----
System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.ServiceHub.HostLib.ServiceLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
-----

Suppress the following diagnostics to disable this analyzer: S3442	(project name)		1	Active

1 Like

Just to add a little bit more info. If instead of the SonarLint extension I use the nuget package everything works fine. I’ve tried to completely remove the extension and reinstalling it (before resorting to use the nuget package) but the error was still the same.
With the nuget packages work but the build times increased a bit so I would prefer to have this using the VS extension.

Also tested this with other people and they got the same error once they updated to version 17.4 of VS 2022.

Can someone please help?

Another extra info:
I’ve confirmed the DLLs on the extension folder on my machine where using version 8.44. I’ve tried to copy the analyzer DLLs from the nuget package to the folder where sonar lint extension resides to bump it to version 8.48 in hopes it would work but alas nothing. The error now mentions version 8.48 instead of 8.44 but the error is the same “FileNotFoundException” so it seems somewhere in the extension code or installer the file is not correctly copied to the correct place or is not registered correctly.

Maybe something change in VS 2022 17.4 on the way the load/register extensions.
Anyway I’m at a loss and I believe I might not be the only one since I’ve seen this bug happen to other people after they updated to 17.4.

I’m seeing the same error since updating to VS 2022 17.4. Getting 271975 warnings and VS is slow and freezing up at times.

If you need a quick solution just disable the extension and use the nuget package on all the projects.
This worked for me as a temporary fix but the build times for my solution increased a bit.

Just installed version 17.4.1 of VS 2022. Problem remains

i have exactly the same behaviour with some installations. the noticeable difference is that the sonarlint dlls are only searched for in the installation directory of visual studio. with installations where the extension works, the vs locations are searched for first and then the user extension directory is searched for and also found. however, copying the extension dlls into the installation directory did not result in the extension working. you can only observe that the required dlls are found and loaded. the error pattern remains the same. hope this hint helps to localise the problem!

1 Like

FYI we encountered this problem on one of our dev machines this afternoon and were able to investigate.

We were getting exactly the same error message:

System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 --->

We attached a debugger and were able to check which Sonar analyzer assemblies were loaded and where they were being loaded from. There are three analyzer assemblies. Two had been loaded by VS from the expected location. The third (SonarAnalyzer.CFG) had not, even though it was in same directory as the calling assembly. We checked that the SonarAnalyzer.CFG assembly was valid (i.e. had not been corrupted).

We then noticed that there were a large number of orphaned Microsoft.ServiceHub.Controller processes (used internally by Visual Studio). We closed Visual Studio, killed all of the orphaned Microsoft.ServiceHub.Controller processes, and restarted Visual Studio.

The analyzer then worked as expected i.e. no exception complaining about SonarAnalyzer.CFG.

We’re not sure what the root cause of the problem is. It could be a problem in the Sonar analyzer, but that seems unlikely (VS is responsible for locating and loading the assemblies). We’ll investigate further if we can reproduce the issue.

In the meantime, if you encounter the problem, try closing down your VS instance and killing any orphaned processes ServiceHub process. Please let us know if that fixes the issue or not. Thanks!

2 Likes

Hi,

I’ve tested with a clean reboot, just opening visual studio with the solutions and the errors start appearing right away. I have my VS analysis scope set to “Entire Solution” so as soon as I open it I guess the analyzers kick in. Anyway just opening the solution starts producing the errors.
This only happens on version 17.4 so maybe something changed on VS side to make this happen. Looking at the release notes for VS 17.4 the only mention of “extensions” is in the new rollback feature. Maybe something worth looking into?

Also as a side note, my colleague did a repair install in VS 17.4 so everything was installed fresh and the same error occurred.

Thanks @Antonio_Albuquerque. I have the issue with VS 17.4.1. I’ll check to see if we’ve seen it with any other versions.

Does it repro if you change the analysis scope to something other than Entire Solution? (it doesn’t for me).

@duncanp Same error even if I change the scope

have been able to solve (or workaround) the problem confirmed in an installation. in the options in the vs under: text editor/c#/advanced a deactivation of the option: code analysis in separate process helps.

if the analysis is done in the vs process space sonarlint works as expected. as soon as this process option is enabled again (i think it is enabled in the default), then the described error pattern occurs.

this behavior can be verified on one system. try to verify this on other systems!

1 Like

Yep, changing that setting works around the issue for me.
Now to find the real solution :slight_smile:

Confirmed. Works for me as well.

Same issue on VS 2022 17.4.1 + Windows 11 latest - 330K notifications of SonarLint crashing, 19GB RAM use, crashed VS.

System.IO.FileNotFoundException: Could not load file or assembly 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'. The system cannot find the file specified.
File name: 'SonarAnalyzer.CFG, Version=8.44.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
 --->

And Dietmar’s fix fixed it👍

Confirmed. Workaround works for me (VS 17.4 64-bit, Windows 10).

thank you for the flowers! i (or my team) have found a workaround. that’s all.

background to our setup for further error analysis:

we have a virtualisation system where the user area and the os area (incl. installations) are placed separately on 2 partitions.

we always update and deploy the os area.

therefore we have the following error pattern:

the part of the vs installation of the user area was still in version < 17.4 (version 17.3) and the vs installation has been upgraded to 17.4. and it is exactly with this constellation that we have (not across the board!) this error picture that the solarlint extension does not work. all other extensions have no problem with this constellation. removing and re-adding,… does not solve the problem any more. as soon as you have run into this error picture, there is no way back. even a downgrade of the vs does not solve the error picture any more.

If a vs update to 17.4 was made before the new os image, then everything works as expected and solarlint runs as expected.

I think (assume) that this error image can also be restored manually by backing up and restoring (copying) the user part (roaming, local,…).

I have the same issue … but I think it had worked at some time.
I just tried re-binding SonarLint - and I am unable to connect to SonarCloud.io … maybe it is related?

SonarLint output window:

Failed to fetch notifications: A task was canceled.
Connecting to SonarQube server: https://sonarcloud.io/
Connecting to SonarQube server: Validating credentials
Connecting to ‘https://sonarcloud.io/’.
SonarQube request timed out or was canceled
Connecting to SonarQube server: Failed
Disconnecting…