From adebe18e0291935d1b7eebd362abfef4b2dacc49 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Fri, 14 Aug 2015 14:09:51 +0100 Subject: [PATCH] Second half of fix to https://github.com/Microsoft/visualfsharp/issues/106 --- src/fsharp/CompileOps.fs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fsharp/CompileOps.fs b/src/fsharp/CompileOps.fs index 99ea401e774..65a5d692dc5 100644 --- a/src/fsharp/CompileOps.fs +++ b/src/fsharp/CompileOps.fs @@ -3846,11 +3846,20 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti referencedAssemblies = [| for r in resolutions.GetAssemblyResolutions() -> r.resolvedPath |] temporaryFolder = Path.GetTempPath() } + // The type provider should not hold strong references to disposed + // TcImport objects. So the callbacks provided in the type provider config + // dispatch via a thunk which gets set to a non-resource-capturing + // failing function when the object is disposed. + let systemRuntimeContainsType = + let systemRuntimeContainsTypeRef = ref tcImports.SystemRuntimeContainsType + tcImports.AttachDisposeAction(fun () -> systemRuntimeContainsTypeRef := (fun _ -> raise (System.ObjectDisposedException("The type provider has been disposed")))) + fun arg -> systemRuntimeContainsTypeRef.Value arg + let providers = [ for assemblyName in providerAssemblies do yield ExtensionTyping.GetTypeProvidersOfAssembly(displayPSTypeProviderSecurityDialogBlockingUI, tcConfig.validateTypeProviders, tpApprovals, fileNameOfRuntimeAssembly, ilScopeRefOfRuntimeAssembly, assemblyName, typeProviderEnvironment, - tcConfig.isInvalidationSupported, tcConfig.isInteractive, tcImports.SystemRuntimeContainsType, systemRuntimeAssemblyVersion, m) ] + tcConfig.isInvalidationSupported, tcConfig.isInteractive, systemRuntimeContainsType, systemRuntimeAssemblyVersion, m) ] let wasApproved = providers |> List.forall (fun (ok,_) -> ok) let providers = providers |> List.map snd |> List.concat