Open
Description
Describe the bug
Native code generation for a NativeAOT project sporadically fails, only to succeed on the next attempt. Here is one example:
https://github.com/AArnott/Nerdbank.MessagePack/actions/runs/15930024840/job/44936689976#step:5:34
Generating native code
EXEC : error : One or more errors occurred. (Code generation failed for method '[S.P.Uri]System.Uri.Equals(object)') [D:\a\Nerdbank.MessagePack\Nerdbank.MessagePack\test\AotCompatibilityTest\AotCompatibilityTest.csproj]
System.AggregateException: One or more errors occurred. (Code generation failed for method '[S.P.Uri]System.Uri.Equals(object)')
---> ILCompiler.CodeGenerationFailedException: Code generation failed for method '[S.P.Uri]System.Uri.Equals(object)'
---> ILCompiler.NativeAotFatalErrorException: ILC: error IL1013: Error processing 'name'.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Xml.XPath.XNodeNavigator.MoveToFirstChild() + 0x22
at MS.Internal.Xml.XPath.XPathChildIterator.MoveNext() + 0x19
at System.Xml.XPath.XPathNodeIterator.Enumerator.MoveNext() + 0xd6
at ILCompiler.ProcessLinkerXmlBase.ProcessAssemblies(XPathNavigator) + 0x15b
at ILCompiler.ProcessLinkerXmlBase.ProcessXml(Boolean) + 0xfa
--- End of inner exception stack trace ---
at ILCompiler.ProcessLinkerXmlBase.ProcessXml(Boolean) + 0x1d9
at ILCompiler.SubstitutionProvider.AssemblyFeatureInfo..ctor(EcmaModule, Logger, IReadOnlyDictionary`2, BodyAndFieldSubstitutions) + 0x1ce
at ILCompiler.SubstitutionProvider.FeatureSwitchHashtable.CreateValueFromKey(EcmaModule) + 0x4e
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey) + 0x18
at ILCompiler.SubstitutionProvider.GetSubstitution(MethodDesc) + 0x77
at ILCompiler.SubstitutedILProvider.GetMethodIL(MethodDesc) + 0x1b
at ILCompiler.Compilation.CombinedILProvider.GetMethodIL(MethodDesc) + 0x21
at ILCompiler.Compilation.ILCache.CreateValueFromKey(MethodDesc) + 0x3c
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey) + 0x18
at ILCompiler.Compilation.GetMethodIL(MethodDesc) + 0xb6
at Internal.IL.ILImporter..ctor(ILScanner, MethodDesc, MethodIL) + 0x55
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode) + 0x57
--- End of inner exception stack trace ---
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode) + 0x22b
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker&, Int64, Boolean&) + 0x10d
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker&, Int64, Boolean&) + 0x4e4
at System.Threading.Tasks.TaskReplicator.Replica.Execute() + 0xb1
--- End of inner exception stack trace ---
at System.Threading.Tasks.TaskReplicator.Run[TState](TaskReplicator.ReplicatableUserAction`1, ParallelOptions, Boolean) + 0x2b2
at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt, TInt, ParallelOptions, Action`1, Action`2, Func`4, Func`1, Action`1) + 0x21f
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection, CancellationToken, Exception) + 0x30
at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt, TInt, ParallelOptions, Action`1, Action`2, Func`4, Func`1, Action`1) + 0x449
at ILCompiler.ILScanner.CompileMultiThreaded(List`1) + 0x264
at ILCompiler.ILScanner.ComputeDependencyNodeDependencies(List`1) + 0x153
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() + 0x159
at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() + 0x1b
at ILCompiler.Program.<Run>g__RunScanner|4_0(Program.<>c__DisplayClass4_0&) + 0x1fa
at ILCompiler.Program.Run() + 0x2906
at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass240_0.<.ctor>b__0(ParseResult) + 0x321
D:\a\Nerdbank.MessagePack\Nerdbank.MessagePack\.nuget\packages\microsoft.dotnet.ilcompiler\9.0.6\build\Microsoft.NETCore.Native.targets(317,5): error MSB3073: The command ""D:\a\Nerdbank.MessagePack\Nerdbank.MessagePack\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.6\tools\\ilc" @"D:\a\Nerdbank.MessagePack\Nerdbank.MessagePack\obj\test\AotCompatibilityTest\Release\net9.0\win-x64\native\AotCompatibilityTest.ilc.rsp"" exited with code 1. [D:\a\Nerdbank.MessagePack\Nerdbank.MessagePack\test\AotCompatibilityTest\AotCompatibilityTest.csproj]
Further technical details
.NET SDK:
Version: 9.0.301
Commit: a596cd22e2
Workload version: 9.0.300-manifests.9bcbba73
MSBuild version: 17.14.5+edd3bbf37
Runtime Environment:
OS Name: Windows
OS Version: 10.0.20348
OS Platform: Windows
RID: win-x64
Base Path: C:\hostedtoolcache\windows\dotnet\sdk\9.0.301\
.NET workloads installed:
[maui-windows]
Installation Source: VS 17.14.36203.30
Manifest Version: 9.0.0/9.0.100
Manifest Path: C:\hostedtoolcache\windows\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.0\WorkloadManifest.json
Install Type: FileBased
[maccatalyst]
Installation Source: VS 17.14.36203.30
Manifest Version: 18.0.9617/9.0.100
Manifest Path: C:\hostedtoolcache\windows\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.0.9617\WorkloadManifest.json
Install Type: FileBased
[ios]
Installation Source: VS 17.14.36203.30
Manifest Version: 18.0.9617/9.0.100
Manifest Path: C:\hostedtoolcache\windows\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.0.9617\WorkloadManifest.json
Install Type: FileBased
[android]
Installation Source: VS 17.14.36203.30
Manifest Version: 35.0.7/9.0.100
Manifest Path: C:\hostedtoolcache\windows\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.7\WorkloadManifest.json
Install Type: FileBased
[wasm-tools]
Installation Source: VS 17.14.36203.30
Manifest Version: 9.0.6/9.0.100
Manifest Path: C:\hostedtoolcache\windows\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.6\WorkloadManifest.json
Install Type: FileBased
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.6
Architecture: x64
Commit: 3875b54e7b
.NET SDKs installed:
9.0.301 [C:\hostedtoolcache\windows\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.6 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.17 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.6 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.17 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.6 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
DOTNET_ROOT [C:\hostedtoolcache\windows\dotnet]
global.json file:
D:\a\Nerdbank.MessagePack\Nerdbank.MessagePack\global.json