Metalama icon indicating copy to clipboard operation
Metalama copied to clipboard

The system cannot open the device or file specified. : 'Global\Metalama.Configuration'

Open craigbehnke opened this issue 3 months ago • 3 comments

I'm running into an issue with builds on my personal machine (MacBook w/ Apple Silicon) failing due to being unable to find 'Global\Metalama.Configuration'. I've tried to Google my way through the problem, but there are no results on Google for "Metalama.Configuration" and only one code reference on GitHub.

At the same time, builds on my CICD system continue to work, which leads me to believe that it is a config or corruption issue on my machine. What should I do/look for in order to address the problem?

Stacktrace

/Users/me/.nuget/packages/metalama.compiler/2024.0.8/tasks/netcore/Microsoft.CSharp.Core.targets(113,5): error :
Unhandled exception. System.IO.IOException: The system cannot open the device or file specified. : 'Global\Metalama.Configuration'
    at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
    at Metalama.Backstage.Utilities.MutexHelper.OpenOrCreateMutex(String mutexName, ILogger logger)
    at Metalama.Backstage.Configuration.ConfigurationManager..ctor(IServiceProvider serviceProvider)
    at Metalama.Backstage.Extensibility.RegisterServiceExtensions.AddConfigurationManager(ServiceProviderBuilder serviceProviderBuilder)
    at Metalama.Backstage.Extensibility.RegisterServiceExtensions.AddDiagnosticsRequirements(ServiceProviderBuilder serviceProviderBuilder, IApplicationInfo applicationInfo)
    at Metalama.Backstage.Extensibility.RegisterServiceExtensions.AddBackstageServices(ServiceProviderBuilder serviceProviderBuilder, BackstageInitializationOptions options)
    at Metalama.Backstage.Extensibility.BackstageServiceFactory.Initialize(BackstageInitializationOptions options, String caller)
    at Metalama.Framework.Engine.Utilities.Diagnostics.BackstageServiceFactoryInitializer.Initialize(BackstageInitializationOptions options)
    at Metalama.Framework.Engine.Pipeline.SourceTransformer.InitializeServices(InitializeServicesContext context)
    at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEmitImpl(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 generators, ImmutableArray`1 transformers, 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) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1526
    at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEmit(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 generators, ImmutableArray`1 transformers, 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\eb506826dec91df2\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1322
    at Microsoft.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1034
    at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 807
    at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.<>c__DisplayClass1_0.<Run>b__0(TextWriter tw) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Shared\Csc.cs:line 28
    at Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[T](Boolean utf8Output, TextWriter textWriter, Func`2 func) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Core\CommandLine\ConsoleUtil.cs:line 53
    at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Shared\Csc.cs:line 28
    at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunLocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Shared\BuildClient.cs:line 196
    at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(IEnumerable`1 originalArguments, BuildPaths buildPaths, TextWriter textWriter, String pipeName) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Shared\BuildClient.cs:line 167
    at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run(IEnumerable`1 arguments, RequestLanguage language, CompileFunc compileFunc, CompileOnServerFunc compileOnServerFunc, ICompilerServerLogger logger) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\Shared\BuildClient.cs:line 116
    at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore(String[] args) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\CSharp\csc\Program.cs:line 37
    at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args) in C:\buildAgent\work\eb506826dec91df2\src\Compilers\CSharp\csc\Program.cs:line 18

What I've tried

  1. Deleting all files within my local repository, and then reapplying only committed files to remove generated files.
  2. Deleting all downloaded packages in /Users/me/.nuget/packages at the same time as step 1 to force new copies to be redownloaded.

Other questions: are there other locations that should be cleaned out in order to fix this issue, or is there something else I should be doing?

craigbehnke avatar Mar 18 '24 21:03 craigbehnke

The problem is with opening a named mutex. Since macOS doesn't natively support those, I believe they are implemented using file locks on temporary files, which could be the source of the problem.

Can you see if running the following code on your mac throws?

var mutexName = @"Global\Metalama.Configuration";

if ( !Mutex.TryOpenExisting( mutexName, out var _ ) )
{
    new Mutex( false, mutexName );
}

If so, does the process have limited access to files on disk, or something like that?

svick avatar Mar 19 '24 10:03 svick

I created a new ASP.NET Core project with only this code and ran it using dotnet run. Here's the output:

Unhandled exception. System.IO.IOException: The system cannot open the device or file specified. : 'Global\Metalama.Configuration'
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at Program.<Main>$(String[] args) in /Users/me/Code/TestMutex/Program.cs:line 5

Just in case it was a permissions issue, I ran the same code using sudo dotnet run, and got the same result.

However, when I ran dotnet run with a different name -- "Global/Random.Name" -- it worked properly, and I was even able to run it repeatedly without encountering into an error.


Update: A hard restart solves it, so it does appear that it is linked to a /tmp file somewhere, or something else that can be cleared out on (re)boot.

craigbehnke avatar Mar 19 '24 19:03 craigbehnke

Thanks for the information. I have reported this issue to the .Net runtime team, hopefully, they will be able to resolve it: https://github.com/dotnet/runtime/issues/100135.

svick avatar Mar 22 '24 11:03 svick