You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On .Net core both analyzers will load the same assembly version:
First assembly loaded: Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7
Second assembly loaded: Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7
on .Net Framework each analyzer will load both versions:
First assembly loaded: Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7
Second assembly loaded: Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7
First assembly loaded: Common, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7
Second assembly loaded: Common, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7
Expected Behavior:
Each analyzer will load the correct version of the dependency and no exception is raised.
This seems to be handled correctly on .Net Framework.
Actual Behavior: warning AD0001: Analyzer 'SecondAnalyzer.SecondAnalyzerAnalyzer' threw an exception of type 'System.IO.FileLoadException' with message 'Could not load file or assembly 'Common, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7'. Could not find or load a specific file. (0x80131621)'.
Additional notes:
the order in which the analyzers are passed to the compiler matters. Using this: /analyzer:"lib\first\Common.dll" /analyzer:"lib\second\SecondAnalyzer.dll" /analyzer:"lib\first\FirstAnalyzer.dll" /analyzer:"lib\second\Common.dll" will make the Version 2.2.0.0 load first and not raise the exception.
The text was updated successfully, but these errors were encountered:
costin-zaharia-sonarsource
changed the title
Calling the compiler with analyzers which reference different versions of same assembly results in FileLoadException
Calling the compiler with analyzers which reference different versions of the same assembly results in FileLoadException
Feb 5, 2020
Version Used:
Steps to Reproduce:
dotnet "C:\Program Files\dotnet\sdk\3.1.101\Roslyn\bincore\csc.dll" Program.cs /r:"%localappdata%\NuGet\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Runtime.dll" /analyzer:"FirstAnalyzer\FirstAnalyzer\FirstAnalyzer\bin\Debug\netstandard2.0\FirstAnalyzer.dll" /analyzer:"FirstAnalyzer\FirstAnalyzer\FirstAnalyzer\bin\Debug\netstandard2.0\Common.dll" /analyzer:"SecondAnalyzer\SecondAnalyzer\SecondAnalyzer\bin\Debug\netstandard2.0\SecondAnalyzer.dll" /analyzer:"SecondAnalyzer\SecondAnalyzer\SecondAnalyzer\bin\Debug\netstandard2.0\Common.dll"
A reproducer can be found here: https://github.com/costin-zaharia-sonarsource/dotnet-core-analyzer-dependency-load/tree/master/src and running the build will also generate a file (debug-output.txt) with the loaded assemblies:
On .Net core both analyzers will load the same assembly version:
on .Net Framework each analyzer will load both versions:
Expected Behavior:
Each analyzer will load the correct version of the dependency and no exception is raised.
This seems to be handled correctly on .Net Framework.
Actual Behavior:
warning AD0001: Analyzer 'SecondAnalyzer.SecondAnalyzerAnalyzer' threw an exception of type 'System.IO.FileLoadException' with message 'Could not load file or assembly 'Common, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fe0417f313f4af7'. Could not find or load a specific file. (0x80131621)'.
Additional notes:
the order in which the analyzers are passed to the compiler matters. Using this:
/analyzer:"lib\first\Common.dll" /analyzer:"lib\second\SecondAnalyzer.dll" /analyzer:"lib\first\FirstAnalyzer.dll" /analyzer:"lib\second\Common.dll"
will make the Version 2.2.0.0 load first and not raise the exception.Work around:
pack all the dependencies with a tool like https://github.com/dotnet/ILMerge
The text was updated successfully, but these errors were encountered: