F# - Using Concurrent.ConcurrentDictionary.TryRemove with dotnet 5

The problem is that .NET 5 added an overload. Before there was only TryRemove (key : 'a, byref<'b> value) : bool, now the new overload TryRemove(item: KeyValuePair<'a, 'b>) : bool gets chosen. See netcore 3.1 vs NET 5

An alternative solution is to add a type annotation, e.g.

let tryRemove (key: 'a) (dict: Concurrent.ConcurrentDictionary<'a, 'b>) =
   match dict.TryRemove(key) with
   | (true, v) -> Some v
   | (false, _) -> None

I have just figured out the:

let mutable v = Unchecked.defaultof<'b>

instead of

let mutable v: 'b = null

works, but it's super strange the simplified syntax with last out argument translated to tuple result does not work anymore. Does it?

EDIT
It still works! See the right answer :)

Tags:

.Net

F#

C# To F#