runtime icon indicating copy to clipboard operation
runtime copied to clipboard

.NET Core 2.0 - Recursive resource lookup bug in System.Private.CoreLib

Open razzemans opened this issue 9 years ago • 8 comments

After releasing the .NET Core 2.0 version of our application, it wouldn't start. The stdout logs show this:

Assert Failure
Expression: [Recursive resource lookup bug]
Description: Infinite recursion during resource lookup within System.Private.CoreLib.  This may be a bug in System.Private.CoreLib, or potentially in certain extensibility points such as assembly resolve events or CultureInfo names.  Resource name: ArgumentNull_Generic
Stack Trace:
   at System.SR.InternalGetResourceString(String key)

   at System.SR.GetResourceString(String resourceKey, String defaultString)

   at System.ArgumentNullException..ctor(String paramName)

   at System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(Assembly assembly)

   at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)

   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)

   at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)

   at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)

   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)

   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)

   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)

   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)

   at System.SR.InternalGetResourceString(String key)

   at System.SR.GetResourceString(String resourceKey, String defaultString)

   at System.ArgumentNullException..ctor(String paramName)

   at System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(Assembly assembly)

   at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)

   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)

   at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)

   at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)

   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)

   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)

   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)

   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)

   at System.SR.InternalGetResourceString(String key)

   at System.SR.GetResourceString(String resourceKey, String defaultString)

   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)

   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)

   at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)

   at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)

   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)

   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)

   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)

   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)

   at System.Resources.ResourceManager.GetString(String name)

   at System.SR.GetResourceString(String resourceKey, String defaultString)

   at System.ComponentModel.DataAnnotations.MinLengthAttribute..ctor(Int32 length)

   at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)

   at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)

   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)

   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)

   at System.Reflection.RuntimePropertyInfo.GetCustomAttributes(Type attributeType, Boolean inherit)

   at System.Attribute.InternalGetCustomAttributes(PropertyInfo element, Type type, Boolean inherit)

   at System.Attribute.GetCustomAttributes(MemberInfo element, Boolean inherit)

   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes(MemberInfo element)

   at Microsoft.AspNetCore.Mvc.ModelBinding.ModelAttributes.GetAttributesForProperty(Type type, PropertyInfo property)

   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.CreatePropertyDetails(ModelMetadataIdentity key)

   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.GetMetadataForProperties(Type modelType)

   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Properties()

   at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexTypeModelBinderProvider.GetBinder(ModelBinderProviderContext context)

   at Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory.CreateBinderCoreUncached(DefaultModelBinderProviderContext providerContext, Object token)

   at Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory.CreateBinder(ModelBinderFactoryContext context)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider.GetParameterBindingInfo(IModelBinderFactory modelBinderFactory, IModelMetadataProvider modelMetadataProvider, ControllerActionDescriptor actionDescriptor)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider.CreateBinderDelegate(ParameterBinder parameterBinder, IModelBinderFactory modelBinderFactory, IModelMetadataProvider modelMetadataProvider, ControllerActionDescriptor actionDescriptor)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerCache.GetCachedResult(ControllerContext controllerContext)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerProvider.OnProvidersExecuting(ActionInvokerProviderContext context)

   at Microsoft.AspNetCore.Mvc.Internal.ActionInvokerFactory.CreateInvoker(ActionContext actionContext)

   at Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler.<>c__DisplayClass8_0.<RouteAsync>b__0(HttpContext c)

   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)

   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.<Invoke>d__3.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Rewrite.RewriteMiddleware.Invoke(HttpContext context)

   at NetEscapades.AspNetCore.SecurityHeaders.Infrastructure.CustomHeadersMiddleware.<Invoke>d__7.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at NetEscapades.AspNetCore.SecurityHeaders.Infrastructure.CustomHeadersMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__4.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__11.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)

   at Microsoft.AspNetCore.HttpOverrides.ForwardedHeadersMiddleware.Invoke(HttpContext context)

   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()

   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)

   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.Invoke(HttpContext httpContext)

   at Microsoft.AspNetCore.Hosting.Internal.HostingApplication.ProcessRequestAsync(Context context)

   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()

   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.<>c.<.cctor>b__4_0(Object sm)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunnerWithContext.RunWithCapturedContext()

   at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.<>c.<.cctor>b__67_3(Object o)

   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.LoggingThreadPool.<>c__DisplayClass6_0.<Schedule>b__0()

   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.LoggingThreadPool.<RunAction>b__3_0(Object o)

   at System.Threading.QueueUApplication is shutting down...

Not sure how to debug this further, it works on our development machine.

razzemans avatar Oct 18 '17 14:10 razzemans

The error you're seeing is likely a manifestation of a security bug that was announced yesterday: https://github.com/dotnet/corefx/issues/24703. That said, it's not supposed to impact .NET Core 2.0 so it's a bit weird.

/cc @blowdart

kevinchalet avatar Oct 18 '17 17:10 kevinchalet

Yea, that bug didn't cause problems in 2.0, and wouldn't have affected sites hosted on Azure Web Apps anyway.

So, afraid not the CVE, it's something else. I'll let normal triage grab this.

blowdart avatar Oct 18 '17 17:10 blowdart

@razzemans this is a dupe of https://github.com/dotnet/corefx/issues/23608 which we expect to be fixed in the servicing release next month. The fix is already in master and release/2.0 branches if building locally is an option for you.

If your app is in en-US culture then you can add just new ArgumentException(); on the first line of main, or before your web app is initialized. This will load neutral resources and work around the problem. If you app is not en-US culture then there is no good workaround, but I know in some cases this was triggered by app insights and temporarily removing that has helped. (This is not a bug in AppInsights, it is just triggering it)

danmoseley avatar Oct 18 '17 21:10 danmoseley

@danmosemsft alright, so go ahead and close this one.

We have removed the Application Insights site extension and will try again. I'm actually quite confused now, didn't even know we had that extension installed and what the difference is between that and just adding the AI NuGet package.

razzemans avatar Oct 19 '17 09:10 razzemans

@razzemans sounds good, I want to emphasize though, there is no defect in app insights and I hope you will re-enable it as soon as you get the 2.0 patch next month.

danmoseley avatar Oct 19 '17 16:10 danmoseley

@danmosemsft We also have Application Insights integrated using NuGet packages instead of using the site extension on Azure. I do wonder if that can still lead to this issue (as we've only had this issue with our application where we had the extension installed), but we'll have to see I guess.

razzemans avatar Oct 20 '17 06:10 razzemans

Fix released https://github.com/dotnet/corefx/releases/tag/v2.0.3

danmoseley avatar Nov 15 '17 21:11 danmoseley

thanks for the feedback!

razzemans avatar Nov 15 '17 22:11 razzemans