-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analyzer host process fails to load analyzers correctly when building in parallel #52177
Comments
.NET Core relies on Assembly Load Context (ALC) to load more than one version of the same assembly side-by-side. Currently the compiler doesn't support ALC for analyzer references, so if more than one analyzer in the project is providing the same dependency, they all need to have the same version. This applies even to the case where strong names can distinguish between the assemblies, which would work side-by-side for .NET Framework builds. |
Does that make this a duplicate of work that is already tracked, or is new work still needed to achieve a "just working" analyzer ecosystem? |
Think we need to just follow the pattern that the MSBuild team laid out here for how they isolated One complication we have to consider though is that analyzers and there dependencies are passed with the
The standard tasks and targets will cause the compiler command line to include both This means that for the purpose of isolating in an Details on how |
I think I know what could work. When trying to load an anaylzer / source generator:
Using this would have benefits:
Cons of this:
|
That approach was considered in 1.0 and rejected for the following reasons:
In the end we decided to stick with first principals here and force all analyzers and their dependencies to be listed with |
I guess another option is for the compiler to check every analyzer first before it runs them for dependencies inside the metadata references to them (like what ILSpy can do for that part), then only load the newest version of each dependency based on the analyzers / sourcegenerators needing to be used then do an implicit runtime "binding redirect" for the rest. |
@AraHaan That still falls foul of Jared's first point:
|
@jnm2 has it right here, still runs afoul of the first pooint. Overall though I want to stress there really isn't a problem with our existing design and making it work with |
I think there could be another option, look for a json file (like what it generates when you target Also it would come with benefits as well:
Cons:
|
@AraHaan overall though you're proposing a solution for a behavior that is not deemed as a problem by us. The build flow here has remain unchanged for ~5 years now. It's not that the existing flow doesn't have the data that would allow us to be successful, it's just that we haven't fully leveraged the data in the .NET Core scenarios to provide maximum flexibility. |
I was able to manually verify that this scenario works with the changes in #55098. I manually referenced an "old" compiler and got it to exhibit the bad behavior, then updated the reference and things started working. |
I've verified that both the minimal repro at the top and the real-world project begin to build successfully under SDK 5.0.302 but not under 5.0.205. If 5.0.302 doesn't have your changes, I guess that means that this particular repro is lost but the underlying problem may show itself in another combination of analyzers and source files. |
Version Used: SDK 5.0.201
This has always worked when running
msbuild
, but it does not work usingdotnet build
. The only workaround I have at the moment is to put/p:BuildInParallel=false
in the dotnet build line which is not great because I want people to be able to walk up and type dotnet build multiple times.<BuildInParallel>false</BuildInParallel>
didn't seem to have any effect on the repro.What would it take to get from here to things just working for consumers of analyzers that have dependencies?
Steps to Reproduce:
Run this (
rebuild
is only to simulate edit + build during development):Expected Behavior:
No warnings.
Actual Behavior:
37 warnings appear, all analyzer crashes due to not being able to load an assembly:
The text was updated successfully, but these errors were encountered: