fsprojects / FAKE

FAKE - F# Make
https://fake.build
Other
1.28k stars 582 forks source link

Fixes #2600 #2690

Closed yazeedobaid closed 1 year ago

yazeedobaid commented 1 year ago

Description

After a hint from @michaelsmithson in this comment, we found the source of the issue that causes the NUnit Console runner to fail.

I commented out that call for withEnvironment in create process and it indeed runs the tests in the given repro repository successfully without issues.

Also, replacing withEnvironment with withEnvironmentMap runs successfully without issues. Further debugging the issue and I got a duplicate item error as shown below:

System.ArgumentException: An item with the same key has already been added.
at System.Runtime.CompilerServices.ConditionalWeakTable`2.Add(TKey key, TValue value)
at Microsoft.FSharp.Control.ExceptionDispatchInfoHelpers.ExceptionDispatchInfo.GetAssociatedSourceException(ExceptionDispatchInfo ) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 48

The withEnvironment method calls EnvMap.ofSeq from the Process module which has the following implementation:

let ofSeq l : EnvMap =
        empty.AddRange(l |> Seq.map (fun (k, v) -> KeyValuePair<_,_>(k, v)))

The empty is a new instance of ImmutableDictionary.

Comparing withEnvironment with withEnvironmentMap implemntations and the only difference is that, before adding the list of given environment variables, the withEnvironmentMap initializes the immutable collection with environment variables.

So, trying to add Clear before adding the given list of environment variables in ofSeq with no luck, Also, checking items in the collection before adding an item and skipping any duplicates, resulted in the same error.

What I ended up doing is initializing the empty immutable collection with environment variables before adding the given environment list. Same as withEnvironmentMap

Another solution would be to just replace the withEnvironment with withEnvironmentMap in NUnit create process. But this will not solve the issue from its roots.

TODO

Feel free to open the PR and ask for help