Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant load non US resources in netcoreapp2.0 #8503

Closed
SimonCropp opened this issue Jul 6, 2017 · 12 comments
Closed

Cant load non US resources in netcoreapp2.0 #8503

SimonCropp opened this issue Jul 6, 2017 · 12 comments

Comments

@SimonCropp
Copy link
Contributor

  • netcoreapp2.0. 2.0.0-preview2-006497
  • console app that is doing some basic assembly loading
  • australia culture

When i run i get the following exception

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.BadImageFormatException..ctor()
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)

If i hack it back to US Culture it runs fine

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
@jkotas
Copy link
Member

jkotas commented Jul 8, 2017

@tarekgh
Copy link
Member

tarekgh commented Jul 10, 2017

@SimonCropp this looks same issue we fixed which @jkotas pointed at dotnet/corefx#21095. could you please try the latest netcoreapp package and let's know if the problem still there or not?

https://www.nuget.org/packages/Microsoft.NETCore.App/2.0.0-preview2-25407-01

Also if you have sample project you can share, we can validate that too. Thanks.

@timbussmann
Copy link

timbussmann commented Jul 21, 2017

I'm seeing the same behavior using preview2-25407-01 using "de-DE" culture

@tarekgh
Copy link
Member

tarekgh commented Jul 21, 2017

@timbussmann could you please share small project repro the issue so we can investigate it? also tell us what OS you are using and which version. Thanks.

@timbussmann
Copy link

@tarekgh I have a repro sample using NServiceBus. I haven't been able to isolate the issue further yet but I simplified my sample as much as possible. I'll try to see whether I can isolate a repro without using NServiceBus on Monday. Here's the repository with the repro: https://github.com/timbussmann/Repro

@tarekgh
Copy link
Member

tarekgh commented Jul 21, 2017

Thanks @timbussmann

Which OS version you are running on? and what is your culture settings? I mean, are you running on de-DE machine?

@timbussmann
Copy link

@tarekgh I'm running on Windows 10 build 14393.1480. I'm using the de-CH region settings. This results in CurrentUICulture being "de-DE", while CurrentCulture is "de-CH" in .net apps.

@tarekgh
Copy link
Member

tarekgh commented Jul 21, 2017

@timbussmann I can repro it with your project. thanks for sharing that.

@tarekgh
Copy link
Member

tarekgh commented Jul 22, 2017

@kouvel is going to look at fixing this issue. I have a simple repro now too.

kouvel referenced this issue in kouvel/coreclr Jul 24, 2017
Part of fix for #12668:
- CoreLib resource lookup should not raise the AssemblyResolve event because a misbehaving handler could cause an infinite recursion check and fail-fast to be triggered when the resource is not found, as the issue would repeat when reporting that error
- A handler could misbehave by returning an assembly that does not match the requested identity or by throwing
kouvel referenced this issue in kouvel/coreclr Jul 24, 2017
Part of fix for #12668:
- CoreLib resource lookup should not raise the AssemblyResolve event because a misbehaving handler could cause an infinite recursion check and fail-fast to be triggered when the resource is not found, as the issue would repeat when reporting that error
- A handler could misbehave by returning an assembly that does not match the requested identity or by throwing
kouvel referenced this issue in kouvel/coreclr Jul 24, 2017
Part of fix for #12668:
- CoreLib resource lookup should not raise the AssemblyResolve event because a misbehaving handler could cause an infinite recursion check and fail-fast to be triggered when the resource is not found, as the issue would repeat when reporting that error
- A handler could misbehave by returning an assembly that does not match the requested identity or by throwing
kouvel referenced this issue in dotnet/coreclr Jul 24, 2017
* Don't call AssemblyResolve event for CoreLib resources

Part of fix for #12668:
- CoreLib resource lookup should not raise the AssemblyResolve event because a misbehaving handler could cause an infinite recursion check and fail-fast to be triggered when the resource is not found, as the issue would repeat when reporting that error
- A handler could misbehave by returning an assembly that does not match the requested identity or by throwing

* Address feedback
kouvel referenced this issue in kouvel/coreclr Jul 25, 2017
* Don't call AssemblyResolve event for CoreLib resources

Part of fix for #12668:
- CoreLib resource lookup should not raise the AssemblyResolve event because a misbehaving handler could cause an infinite recursion check and fail-fast to be triggered when the resource is not found, as the issue would repeat when reporting that error
- A handler could misbehave by returning an assembly that does not match the requested identity or by throwing

* Address feedback
kouvel referenced this issue in dotnet/coreclr Aug 17, 2017
Don't call AssemblyResolve event for CoreLib resources

Part of fix for #12668:
- CoreLib resource lookup should not raise the AssemblyResolve event because a misbehaving handler could cause an infinite recursion check and fail-fast to be triggered when the resource is not found, as the issue would repeat when reporting that error
- A handler could misbehave by returning an assembly that does not match the requested identity or by throwing
@karelz
Copy link
Member

karelz commented Aug 25, 2017

@tarekgh was it fixed in 2.0.0, or do we need to make more changes in servicing?

@kouvel
Copy link
Member

kouvel commented Aug 25, 2017

This should be fixed in the 2.0.0 branch now, it wasn't auto-closed by dotnet/corefx#22553 for some reason. Going ahead and closing.

@kouvel kouvel closed this as completed Aug 25, 2017
@danmoseley
Copy link
Member

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

zacharycmontoya referenced this issue in DataDog/dd-trace-dotnet Dec 2, 2019
…rlib resource lookup (#573)

Modifies the AssemblyResolve event handler in the Datadog.Trace.ClrProfiler.Managed.Loader assembly to eagerly exit if the requested assembly is `mscorlib.resources` or `System.Private.CoreLib.resources` on .NET Framework and .NET Core, respectively.

This fixes a known issue where on a non-US locale, a lookup of an `mscorlib` resource invokes the AssemblyResolve event and our event handler causes infinite recursion and the .NET application to crash. This occurred because, in processing the event, the event handler would make a method call to `File.Exists`, which triggers yet another AssemblyResolve event for `mscorlib` and the cycle continues. Even though this has only been demonstrated to occur on .NET Framework and should not occur on .NET Core 2.0+ (see https://github.com/dotnet/coreclr/issues/12668), proactively guard against AssemblyResolve events for `System.Private.CoreLib.resources` as well.
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 2.0.x milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants