From 7c1f5c190d54e35907461b1cc9146ed302d1a236 Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Wed, 27 Sep 2017 19:48:51 -0700 Subject: [PATCH 1/2] Fix stack overflow on tp assembly resolution --- src/utils/reshapedreflection.fs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/reshapedreflection.fs b/src/utils/reshapedreflection.fs index 7f0eb87c052..4cff60178c7 100644 --- a/src/utils/reshapedreflection.fs +++ b/src/utils/reshapedreflection.fs @@ -48,6 +48,10 @@ module internal ReflectionAdapters = let isStaticFlag f = hasFlag BindingFlags.Static f let isInstanceFlag f = hasFlag BindingFlags.Instance f let isNonPublicFlag f = hasFlag BindingFlags.NonPublic f + + let isOldCorlib = + let attributes = typeof.GetTypeInfo().Assembly.GetCustomAttributes() |> Seq.toArray + if attributes.Length = 0 then false else attributes.[0].Version = "4.6.24410.01" #if FX_NO_TYPECODE [] @@ -327,7 +331,14 @@ module internal ReflectionAdapters = override this.Load (assemblyName:AssemblyName):Assembly = this.LoadFromAssemblyName(assemblyName) - let globalLoadContext = new CustomAssemblyResolver() + let globalLoadContext = + // This is an unfortunate temporary fix!!!! + // ======================================== + // We need to run fsi tests on a very old version of the corclr because of an unfortunate test framework + // This hack detects that, and uses the old code. + // On slightly newer code AssemblyLoadContext.Default is the way to go. + if isOldCorlib then new CustomAssemblyResolver() :> AssemblyLoadContext + else AssemblyLoadContext.Default #endif type System.Reflection.Assembly with From f32b00faa7816caff06c4c0844bf01aeed55f92f Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Thu, 28 Sep 2017 10:59:59 -0700 Subject: [PATCH 2/2] Feedback --- src/utils/reshapedreflection.fs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/utils/reshapedreflection.fs b/src/utils/reshapedreflection.fs index 4cff60178c7..19be659bfd6 100644 --- a/src/utils/reshapedreflection.fs +++ b/src/utils/reshapedreflection.fs @@ -48,10 +48,6 @@ module internal ReflectionAdapters = let isStaticFlag f = hasFlag BindingFlags.Static f let isInstanceFlag f = hasFlag BindingFlags.Instance f let isNonPublicFlag f = hasFlag BindingFlags.NonPublic f - - let isOldCorlib = - let attributes = typeof.GetTypeInfo().Assembly.GetCustomAttributes() |> Seq.toArray - if attributes.Length = 0 then false else attributes.[0].Version = "4.6.24410.01" #if FX_NO_TYPECODE [] @@ -337,8 +333,9 @@ module internal ReflectionAdapters = // We need to run fsi tests on a very old version of the corclr because of an unfortunate test framework // This hack detects that, and uses the old code. // On slightly newer code AssemblyLoadContext.Default is the way to go. - if isOldCorlib then new CustomAssemblyResolver() :> AssemblyLoadContext - else AssemblyLoadContext.Default + match Seq.tryHead (typeof.GetTypeInfo().Assembly.GetCustomAttributes()) with + | Some a when a.Version = "4.6.24410.01" -> new CustomAssemblyResolver() :> AssemblyLoadContext + | _ -> AssemblyLoadContext.Default #endif type System.Reflection.Assembly with