Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 0cc887a

Browse files
brettfonosami
authored andcommitted
don't auto-resolve types from System.Runtime.WindowsRuntime (dotnet#9644)
1 parent b114182 commit 0cc887a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/fsharp/DotNetFrameworkDependencies.fs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,23 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
259259
if not (assemblies.ContainsKey(referenceName)) then
260260
try
261261
if File.Exists(path) then
262-
// System.Private.CoreLib doesn't load with reflection
263-
if referenceName = "System.Private.CoreLib" then
262+
match referenceName with
263+
| "System.Runtime.WindowsRuntime"
264+
| "System.Runtime.WindowsRuntime.UI.Xaml" ->
265+
// The Windows compatibility pack included in the runtime contains a reference to
266+
// System.Runtime.WindowsRuntime, but to properly use that type the runtime also needs a
267+
// reference to the Windows.md meta-package, which isn't referenced by default. To avoid
268+
// a bug where types from `Windows, Version=255.255.255.255` can't be found we're going to
269+
// not default include this assembly. It can still be manually referenced if it's needed
270+
// via the System.Runtime.WindowsRuntime NuGet package.
271+
//
272+
// In the future this branch can be removed because WinRT support is being removed from the
273+
// .NET 5 SDK (https://github.com/dotnet/runtime/pull/36715)
274+
()
275+
| "System.Private.CoreLib" ->
276+
// System.Private.CoreLib doesn't load with reflection
264277
assemblies.Add(referenceName, path)
265-
else
278+
| _ ->
266279
try
267280
let asm = System.Reflection.Assembly.LoadFrom(path)
268281
assemblies.Add(referenceName, path)

tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ type CompletionTests() =
3131
Assert.AreEqual(1, matchingCompletions.Length)
3232
} |> Async.StartAsTask :> Task
3333

34+
[<Test>]
35+
member _.``Completions from types that try to pull in Windows runtime extensions``() =
36+
async {
37+
use script = new FSharpScript()
38+
script.Eval("open System") |> ignoreValue
39+
script.Eval("let t = TimeSpan.FromHours(1.0)") |> ignoreValue
40+
let! completions = script.GetCompletionItems("t.", 1, 2)
41+
let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "TotalHours")
42+
Assert.AreEqual(1, matchingCompletions.Length)
43+
} |> Async.StartAsTask :> Task
44+
3445
[<Test>]
3546
member _.``Static member completions``() =
3647
async {

0 commit comments

Comments
 (0)