Description
Description
In an application under the configuration described below, one log shows that a TypeInitializationException
was thrown when the type initializer for CDSCollectionETWBCLProvider
ran (because of a NullReferenceException
in InvokeStub_EventSourceAttribute.set_Guid
). It was thrown when the ASP.NET Core app is shutting down (ApplicationLifetime.StopApplication
). As it occurs in the type initializer of CDSCollectionETWBCLProvider
, I'm filing it here in the .NET runtime repository.
Reproduction Steps
I am unfortunately not able to reproduce the error. But maybe looking at the stack trace in combination with the source code leads to some realization.
Expected behavior
The type initializer for CDSCollectionETWBCLProvider
should not throw an exception.
Actual behavior
The type initializer for CDSCollectionETWBCLProvider
threw an exception.
Microsoft.Extensions.Hosting.Internal.ApplicationLifetime An error occurred stopping the application
System.AggregateException: One or more errors occurred. (The type initializer for 'System.Collections.Concurrent.CDSCollectionETWBCLProvider' threw an exception.)
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
at Microsoft.Extensions.Hosting.Internal.ApplicationLifetime.StopApplication()
System.TypeInitializationException: The type initializer for 'System.Collections.Concurrent.CDSCollectionETWBCLProvider' threw an exception.
at System.Collections.Concurrent.ConcurrentDictionary`2.AcquireAllLocks(Int32& locksAcquired)
at System.Collections.Concurrent.ConcurrentDictionary`2.get_Count()
at Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager.CloseConnections()
at System.Threading.CancellationTokenSource.Invoke(Delegate d, Object state, CancellationTokenSource source)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
System.Reflection.CustomAttributeFormatException: 'Guid' property specified was not found.
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit)
at System.Diagnostics.Tracing.EventSource.GetCustomAttributeHelper(MemberInfo member, Type attributeType, EventManifestOptions flags)
at System.Diagnostics.Tracing.EventSource.GetName(Type eventSourceType, EventManifestOptions flags)
at System.Diagnostics.Tracing.EventSource..ctor(EventSourceSettings settings, String[] traits)
at System.Collections.Concurrent.CDSCollectionETWBCLProvider..cctor()
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
System.NullReferenceException: Object reference not set to an instance of an object.
at InvokeStub_EventSourceAttribute.set_Guid(Object, Object, IntPtr*)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
Regression?
No response
Known Workarounds
No response
Configuration
- .NET 8.0.8
- Docker parent image
mcr.microsoft.com/dotnet/aspnet:8.0.8
- The
linux/amd64
version of the image ran under Docker Desktop on macOS 15.0.1 (Apple M2 Pro), Rosetta enabled
Other information
No response