Skip to content

Commit

Permalink
don't auto-resolve types from System.Runtime.WindowsRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo committed Jul 7, 2020
1 parent 8077622 commit e3bb567
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/fsharp/DotNetFrameworkDependencies.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ type CompletionTests() =
Assert.AreEqual(1, matchingCompletions.Length)
} |> Async.StartAsTask :> Task

[<Test>]
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

[<Test>]
member _.``Static member completions``() =
async {
Expand Down

0 comments on commit e3bb567

Please sign in to comment.