diff --git a/src/fsharp/DotNetFrameworkDependencies.fs b/src/fsharp/DotNetFrameworkDependencies.fs index 06e23bb55e22..938d3d9f1d9f 100644 --- a/src/fsharp/DotNetFrameworkDependencies.fs +++ b/src/fsharp/DotNetFrameworkDependencies.fs @@ -259,10 +259,22 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies if not (assemblies.ContainsKey(referenceName)) then try if File.Exists(path) then - // System.Private.CoreLib doesn't load with reflection - if referenceName = "System.Private.CoreLib" then + match referenceName with + | "System.Runtime.WindowsRuntime" -> + // The Windows compatibility pack included in the runtime contains a reference to + // System.Runtime.WindowsRuntime, but to properly use that type the runtime also needs a + // reference to the Windows.md meta-package, which isn't referenced by default. To avoid + // a bug where types from `Windows, Version=255.255.255.255` can't be found we're going to + // not default include this assembly. It can still be manually referenced if it's needed + // via the System.Runtime.WindowsRuntime NuGet package. + // + // In the future this branch can be removed because WinRT support is being removed from the + // .NET 5 SDK (https://github.com/dotnet/runtime/pull/36715) + () + | "System.Private.CoreLib" -> + // System.Private.CoreLib doesn't load with reflection assemblies.Add(referenceName, path) - else + | _ -> try let asm = System.Reflection.Assembly.LoadFrom(path) assemblies.Add(referenceName, path) diff --git a/tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs b/tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs index cd7da3c7d3a4..03935ee77f01 100644 --- a/tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs +++ b/tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs @@ -31,6 +31,17 @@ type CompletionTests() = Assert.AreEqual(1, matchingCompletions.Length) } |> Async.StartAsTask :> Task + [] + member _.``Completions from types that try to pull in Windows runtime extensions``() = + async { + use script = new FSharpScript() + script.Eval("open System") |> ignoreValue + script.Eval("let t = TimeSpan.FromHours(1.0)") |> ignoreValue + let! completions = script.GetCompletionItems("t.", 1, 2) + let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "TotalHours") + Assert.AreEqual(1, matchingCompletions.Length) + } |> Async.StartAsTask :> Task + [] member _.``Static member completions``() = async {