Skip to content

Race in RuntimeTypeCache / metadata reading #81884

@marek-safar

Description

@marek-safar

It happened to me twice but could not reproduce it reliably.

__DistroRid: osx-arm64
  Determining projects to restore...
  Unhandled exception: System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
   ---> System.NullReferenceException: Object reference not set to an instance of an object.
     at System.RuntimeType.get_IsGenericTypeDefinition()
     at System.RuntimeType.MakeGenericType(Type[] instantiation)
     at System.RuntimeType.RuntimeTypeCache.MemberInfoCache`1.PopulateInterfaces(Filter filter)
     at System.RuntimeType.RuntimeTypeCache.MemberInfoCache`1.GetListByName(Char* pName, Int32 cNameLen, Byte* pUtf8Name, Int32 cUtf8Name, MemberListType listType, CacheType cacheType)
     at System.RuntimeType.RuntimeTypeCache.MemberInfoCache`1.Populate(String name, MemberListType listType, CacheType cacheType)
     at System.RuntimeType.GetInterfaces()
     at System.Text.Json.Reflection.ReflectionExtensions.GetCompatibleGenericInterface(Type type, Type interfaceType)
     at System.Text.Json.Serialization.IAsyncEnumerableConverterFactory.CanConvert(Type typeToConvert)
     at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetBuiltInConverter(Type typeToConvert)
     at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetConverterForType(Type typeToConvert, JsonSerializerOptions options, Boolean resolveJsonConverterAttribute)
     at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateJsonTypeInfo(Type type, JsonSerializerOptions options)
     at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options)
     at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type)
     at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
     at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Boolean resolveIfMutable)
     at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
     at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
     at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
     at Microsoft.DotNet.ToolPackage.LocalToolsResolverCache.GetCacheTable(String packageCacheFile)
     at Microsoft.DotNet.ToolPackage.LocalToolsResolverCache.TryLoad(RestoredCommandIdentifier restoredCommandIdentifier, RestoredCommand& restoredCommand)
     at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.PackageHasBeenRestored(ToolManifestPackage package, String targetFramework)
     at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.InstallPackages(ToolManifestPackage package, Nullable`1 configFile)
     at System.Linq.Parallel.SelectQueryOperator`2.SelectQueryOperatorResults.GetElement(Int32 index)
     at System.Linq.Parallel.QueryResults`1.get_Item(Int32 index)
     at System.Linq.Parallel.PartitionedDataSource`1.ListContiguousIndexRangeEnumerator.MoveNext(T& currentElement, Int32& currentKey)
     at System.Linq.Parallel.StopAndGoSpoolingTask`2.SpoolingWork()
     at System.Linq.Parallel.SpoolingTaskBase.Work()
     at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
     at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location ---
     at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
     --- End of inner exception stack trace ---
     at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
     at System.Linq.Parallel.SpoolingTask.SpoolStopAndGo[TInputOutput,TIgnoreKey](QueryTaskGroupState groupState, PartitionedStream`2 partitions, SynchronousChannel`1[] channels, TaskScheduler taskScheduler)
     at System.Linq.Parallel.DefaultMergeHelper`2.System.Linq.Parallel.IMergeHelper<TInputOutput>.Execute()
     at System.Linq.Parallel.MergeExecutor`1.Execute()
     at System.Linq.Parallel.MergeExecutor`1.Execute[TKey](PartitionedStream`2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId)
     at System.Linq.Parallel.PartitionedStreamMerger`1.Receive[TKey](PartitionedStream`2 partitionedStream)
     at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
     at System.Linq.Parallel.QueryOperator`1.ExecuteAndGetResultsAsArray()
     at System.Linq.ParallelEnumerable.ToArray[TSource](ParallelQuery`1 source)
     at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.Execute()
     at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
  --- End of stack trace from previous location ---
     at Microsoft.DotNet.Cli.Parser.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
  --- End of stack trace from previous location ---
     at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseHelp>b__0>d.MoveNext()
  --- End of stack trace from previous location ---
     at System.CommandLine.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__17_0>d.MoveNext()
  --- End of stack trace from previous location ---
     at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseParseDirective>b__0>d.MoveNext()
  --- End of stack trace from previous location ---
     at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()

Version: 8.0.100-alpha.1.23068.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions