dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.03k stars 4.03k forks source link

CompilationAction not Triggering #4068

Closed suprak closed 9 years ago

suprak commented 9 years ago

I'm running into an issue with VS 2015 + Roslyn v1.

I read through the analyzer semantic documentation[1].

According to it, I expect that the compilation action I registered in the Initializer, to be executed once at the end of a compilation.

However I am not getting this behavior. The StartCompilation action gets called, but the End never does. Is this a bug? Am I doing it wrong?

        public override void Initialize(AnalysisContext context)
        {
            context.RegisterCompilationAction(this.OnCompilation);
            context.RegisterCompilationStartAction(this.OnStartCompilation);
        }

[1] https://github.com/dotnet/roslyn/blob/master/docs/analyzers/Analyzer%20Actions%20Semantics.md

KrisVandermotten commented 6 years ago

I set breakpoints in both methods, and only the Start Compilation one fires.

I had the same issue today. However, in my case I have proof that the compilation end action does execute: it reports diagnostics. It's just that breakpoints don't get hit.

I tried everything I could think of: compiling against net47 instead of netstandard1.3, enabling native code debugging, using Debugger.Break(), even throw null; and several combinations of the above. Even though the code does execute, the second breakpoint doesn't get hit.

heejaechang commented 6 years ago

@KrisVandermotten all compilation wide work happens out of proc (ServiceHub.RoslynCodeAnalysisServiceXX.exe) due to its heavy allocation potentials. you need to set breakpoint on that process to debug it.

Hjorthen commented 6 years ago

@heejaechang Do you know if there is a way to simplify attaching to this external process? I am currently making it wait for a debugger using

 while(!Debugger.IsAttached)
            {
                Task.Delay(100).Wait();
            }

from the beginning of the CompilationAction callback, then attaching to it. I am just curious if there is a better way.

heejaechang commented 6 years ago

the external process will start as soon as a solution is opened. and CompilationAction call back will be called every time you modify code in VS. so I dont think you need "Wait" like the above?

or, are you asking whether there is a way to attach 2 processes (VS and the RoslynCodeAnalysisService) at the same time?

Hjorthen commented 6 years ago

I did not realize it was started with the solution. That simplifies things, thanks! 👍