postsharp / Metalama

Metalama is a Roslyn-based meta-programming framework. Use this repo to report bugs or ask questions.
164 stars 4 forks source link

[Bug] InvalidOperationException ... is in invalid state. #210

Closed WhitWaldo closed 10 months ago

WhitWaldo commented 10 months ago

I've got an aspect that builds locally without issue. I'm attempting to apply it to a target class in another assembly.

Unfortunately, when I either build the project or attempt to view the Metalama diff, I receive the following exception:

Severity Code Description Project File Line Suppression State Error LAMA0001 Unexpected exception occurred in Metalama: 'The directory 'C:\Users\whit\AppData\Local\Temp\Metalama\CompileTime\Metalama.Extensions.DependencyIn.netstandard2.0\fee825c088590cea\2023.3.2-preview' is in invalid state. Terminate all build processes, delete the directory and retry the build. Exception details are in 'C:\Users\whit\AppData\Local\Temp\Metalama\CrashReports\2023.3.2-preview\exception-798851a7-d8c3-4f42-a24d-acb943960bae.txt'. Please report this issue at https://www.postsharp.net/support and attach this file to the ticket. You may want to remove sensitive data from the report. UserManager C:\Users\whit_\source\repos...\UserManager\CSC 1 Active

There are only two files in that directory: image

Apparently I'm unable to delete them without closing the entire VS process, which makes this a very annoying bug.

Here's the larger stack trace from the exception:

StreamJsonRpc.RemoteInvocationException: 'The directory 'C:\Users\whit_\AppData\Local\Temp\Metalama\CompileTime\Metalama.Extensions.DependencyIn\.netstandard2.0\fee825c088590cea\2023.3.2-preview' is in invalid state. Terminate all build processes, delete the directory and retry the build.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`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 Metalama.Framework.DesignTime.VisualStudio.Preview.UserProcessTransformationPreviewService.<PreviewTransformationAsync>d__2.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 Metalama.Framework.DesignTime.Contracts.Preview.TransformationPreviewServiceExtensions.<PreviewTransformationAsync>d__0.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 Metalama.Vsx.Preview.PreviewCommand.<ExecuteCoreAsync>d__7.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 Metalama.Vsx.Preview.PreviewCommand.<Execute_Source>d__6.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 Metalama.Vsx.Preview.PreviewCommand.<Execute>d__5.MoveNext()
RPC server exception:
System.InvalidOperationException: 'The directory 'C:\Users\whit_\AppData\Local\Temp\Metalama\CompileTime\Metalama.Extensions.DependencyIn\.netstandard2.0\fee825c088590cea\2023.3.2-preview' is in invalid state. Terminate all build processes, delete the directory and retry the build.
      at Metalama.Framework.Engine.CompileTime.CompileTimeProject..ctor(ProjectServiceProvider serviceProvider, CompileTimeDomain domain, AssemblyIdentity runTimeIdentity, AssemblyIdentity compileTimeIdentity, IReadOnlyList`1 references, CompileTimeProjectManifest manifest, String compiledAssemblyPath, ITextMapFileProvider mapFileProvider, String directory, CacheableTemplateDiscoveryContextProvider cacheableTemplateDiscoveryContextProvider, Assembly assembly, DiagnosticManifest diagnosticManifest)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryDeserializeCompileTimeProject(AssemblyIdentity runTimeAssemblyIdentity, Stream resourceStream, IDiagnosticAdder diagnosticAdder, Boolean cacheOnly, CacheableTemplateDiscoveryContextProvider cacheableTemplateDiscoveryContextProvider, CompileTimeProject& project, CancellationToken cancellationToken)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProjectFromPath(String assemblyPath, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProject(MetadataReference reference, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& referencedProject)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryDeserializeCompileTimeProject(AssemblyIdentity runTimeAssemblyIdentity, Stream resourceStream, IDiagnosticAdder diagnosticAdder, Boolean cacheOnly, CacheableTemplateDiscoveryContextProvider cacheableTemplateDiscoveryContextProvider, CompileTimeProject& project, CancellationToken cancellationToken)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProjectFromPath(String assemblyPath, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProject(MetadataReference reference, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& referencedProject)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProjectFromCompilation(ClassifyingCompilationContext compilationContext, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject)
      at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryBuild(Compilation compilation, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProjectRepository& loader)
      at Metalama.Framework.Engine.Pipeline.AspectPipeline.TryInitialize(IDiagnosticAdder diagnosticAdder, Compilation compilation, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, CancellationToken cancellationToken, AspectPipelineConfiguration& configuration)
      at Metalama.Framework.DesignTime.Pipeline.DesignTimeAspectPipeline.TryInitialize(IDiagnosticAdder diagnosticAdder, Compilation compilation, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, CancellationToken cancellationToken, AspectPipelineConfiguration& configuration)
      at Metalama.Framework.DesignTime.Pipeline.DesignTimeAspectPipeline.PipelineState.GetConfiguration(PipelineState& state, Compilation compilation, Boolean ignoreStatus, TestableCancellationToken cancellationToken)
      at Metalama.Framework.DesignTime.Pipeline.DesignTimeAspectPipeline.GetConfigurationAsync(PartialCompilation compilation, Boolean ignoreStatus, AsyncExecutionContext executionContext, TestableCancellationToken cancellationToken)
      at Metalama.Framework.DesignTime.Pipeline.DesignTimeAspectPipeline.GetConfigurationAsync(PartialCompilation compilation, Boolean ignoreStatus, AsyncExecutionContext executionContext, TestableCancellationToken cancellationToken)
      at Metalama.Framework.DesignTime.Preview.PreviewPipelineBasedService.PrepareExecutionAsync(ProjectKey projectKey, String syntaxTreeName, TestableCancellationToken cancellationToken)
      at Metalama.Framework.DesignTime.Preview.TransformationPreviewServiceImpl.PreviewTransformationAsync(ProjectKey projectKey, String syntaxTreeName, TestableCancellationToken cancellationToken)

And the crash report:

Metalama Version: 2023.3.2-preview
Runtime: .NET Framework 4.8.9167.0
Processor Architecture: X64
OS Description: Microsoft Windows 10.0.19045 
OS Architecture: X64
Exception type: System.InvalidOperationException
Exception message: 'The directory 'C:\Users\whit_\AppData\Local\Temp\Metalama\CompileTime\Metalama.Extensions.DependencyIn\.netstandard2.0\fee825c088590cea\2023.3.2-preview' is in invalid state. Terminate all build processes, delete the directory and retry the build.
===== Exception ===== 
System.InvalidOperationException: 'The directory 'C:\Users\whit_\AppData\Local\Temp\Metalama\CompileTime\Metalama.Extensions.DependencyIn\.netstandard2.0\fee825c088590cea\2023.3.2-preview' is in invalid state. Terminate all build processes, delete the directory and retry the build.
   at Metalama.Framework.Engine.CompileTime.CompileTimeProject..ctor(ProjectServiceProvider serviceProvider, CompileTimeDomain domain, AssemblyIdentity runTimeIdentity, AssemblyIdentity compileTimeIdentity, IReadOnlyList`1 references, CompileTimeProjectManifest manifest, String compiledAssemblyPath, ITextMapFileProvider mapFileProvider, String directory, CacheableTemplateDiscoveryContextProvider cacheableTemplateDiscoveryContextProvider, Assembly assembly, DiagnosticManifest diagnosticManifest)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryDeserializeCompileTimeProject(AssemblyIdentity runTimeAssemblyIdentity, Stream resourceStream, IDiagnosticAdder diagnosticAdder, Boolean cacheOnly, CacheableTemplateDiscoveryContextProvider cacheableTemplateDiscoveryContextProvider, CompileTimeProject& project, CancellationToken cancellationToken)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProjectFromPath(String assemblyPath, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProject(MetadataReference reference, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& referencedProject)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProject(AssemblyIdentity runTimeAssemblyIdentity, IDiagnosticAdder diagnosticAdder, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryDeserializeCompileTimeProject(AssemblyIdentity runTimeAssemblyIdentity, Stream resourceStream, IDiagnosticAdder diagnosticAdder, Boolean cacheOnly, CacheableTemplateDiscoveryContextProvider cacheableTemplateDiscoveryContextProvider, CompileTimeProject& project, CancellationToken cancellationToken)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProjectFromPath(String assemblyPath, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProject(MetadataReference reference, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& referencedProject)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProjectFromCompilation(ClassifyingCompilationContext compilationContext, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryBuild(Compilation compilation, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProjectRepository& loader)
   at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Create(CompileTimeDomain domain, ProjectServiceProvider serviceProvider, Compilation compilation, IDiagnosticAdder diagnostics, Boolean cacheOnly, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, CancellationToken cancellationToken)
   at Metalama.Framework.Engine.Pipeline.AspectPipeline.TryInitialize(IDiagnosticAdder diagnosticAdder, Compilation compilation, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList`1 compileTimeTreesHint, CancellationToken cancellationToken, AspectPipelineConfiguration& configuration)
   at Metalama.Framework.Engine.Pipeline.CompileTime.CompileTimeAspectPipeline.<ExecuteAsync>d__2.MoveNext()
WhitWaldo commented 10 months ago

So, here's where this stands. I closed all my VS instances and rebooted my machine and was able to delete the directory per the error message.

Ever since then, my local aspect project refuses to build with the following message locally (works fine on the build server):

1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error : Unhandled Exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error : Parameter name: span
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.SyntaxNode.FindNode(TextSpan span, Boolean findInsideTrivia, Boolean getInnermostNodeForTie) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\Portable\Syntax\SyntaxNode.cs:line 962
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.MapDiagnosticToFinalCompilation(Diagnostic diagnostic, Compilation compilation, ILogWriter trace) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 2125
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.MapDiagnosticsToFinalCompilation(DiagnosticBag sourceDiagnostics, DiagnosticBag targetDiagnostics, Compilation compilation, ILogger logger) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 2249
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEmitImpl(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 generators, ImmutableArray`1 transformers, ImmutableArray`1 plugins, ImmutableArray`1 additionalTextFiles, AnalyzerConfigSet analyzerConfigSet, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 embeddedTexts, DiagnosticBag diagnostics, ErrorLogger errorLogger, CancellationToken cancellationToken, CancellationTokenSource& analyzerCts, AnalyzerDriver& analyzerDriver, Nullable`1& generatorTimingInfo, IServiceProvider& serviceProvider, ILogger& logger) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1598
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEmit(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 generators, ImmutableArray`1 transformers, ImmutableArray`1 plugins, ImmutableArray`1 additionalTextFiles, AnalyzerConfigSet analyzerConfigSet, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 embeddedTexts, DiagnosticBag diagnostics, ErrorLogger errorLogger, CancellationToken cancellationToken, CancellationTokenSource& analyzerCts, AnalyzerDriver& analyzerDriver, Nullable`1& generatorTimingInfo) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1385
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1113
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 735
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.<>c__DisplayClass1_0.<Run>b__0(TextWriter tw) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Shared\Csc.cs:line 28
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[T](Func`2 func) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Core\CommandLine\ConsoleUtil.cs:line 26
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Shared\Csc.cs:line 28
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunLocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Shared\BuildClient.cs:line 198
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(IEnumerable`1 originalArguments, BuildPaths buildPaths, TextWriter textWriter, String pipeName) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Shared\BuildClient.cs:line 164
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run(IEnumerable`1 arguments, RequestLanguage language, CompileFunc compileFunc, CompileOnServerFunc compileOnServerFunc, ICompilerServerLogger logger) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\Shared\BuildClient.cs:line 105
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore(String[] args) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\CSharp\csc\Program.cs:line 39
1>C:\Users\whit_\.nuget\packages\metalama.compiler\2023.3.2-preview\tasks\net472\Microsoft.CSharp.Core.targets(80,5): error :    at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args) in C:\buildAgent\work\62cb8f15a7eb0a2e\src\Compilers\CSharp\csc\Program.cs:line 20
WhitWaldo commented 10 months ago

I tried uninstalling the NuGet package and reinstalling it (2023.3.2-preview) and I still see the same error (no new crash reports appearing).

Only by downgrading to 2023.3.1-preview does the error finally go away and let the project build locally without any other change to the aspect.

svick commented 10 months ago

Thanks for reporting. We will take a look at both problems.

For the ArgumentOutOfRangeException in Metalama.Compiler, do you have any more information about what's triggering the bug?

WhitWaldo commented 10 months ago

Not a clue - it kept pointing at the .targets build file, but nothing in there seemed out of the norm. Again, identical code checked into the build server built without issue - presumably it only stopped working locally because I'd deleted the directory I'd been directed to in the earlier message, so maybe some dependency on that?

Locally though, I was only able to get it to build again (again, no changes to the aspect itself, just a Nuget package swap) by installing the latest .1-preview and abandoning the .2-preview altogether.

gfraiteur commented 10 months ago

Solved in 2023.3.4-preview.