Skip to content

use binding for IAsyncDisposable not supported in F# interactive #14454

@pedersorensen

Description

@pedersorensen

task computation expressions do not support use or use! bindings for the IAsyncDisposable interface when used in F# interactive.

Repro steps

Make a type that implements IAsyncDisposable and bind it with a use or use! within a task CE:

open System
open System.Threading.Tasks

let asyncDisposable =
  { new IAsyncDisposable with
      member _.DisposeAsync() =
        printfn "Disposing async"
        ValueTask() }

let t = task {
  use d = asyncDisposable
  return ()
}

Expected behavior

The code should compile.

Actual behavior

Error message in both the editor and F# interactive output window

image

>> 

Script1.fsx(11,11): error FS0001: The type 'IAsyncDisposable' is not compatible with the type 'IDisposable'

Known workarounds

Use a let binding and call DisposeAsync explicitly, although this is not possible within a finally block.

Related information

Compiles and runs without issue in regular .fs files.

  • Operating system: Windows 11, 22H2
  • .NET Runtime kind: .NET 7.0.100, F# Interactive version 12.4.0.0 for F# 7.0
  • Visual Studio Professional, 17.4.2
>> dotnet --info
.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-SetupAndDeliverySetup, packages, templates, SDK, delivery channelsBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions