interactive icon indicating copy to clipboard operation
interactive copied to clipboard

🐛Bug: Unable to install/reference `System.Threading.Tasks.Dataflow` library in interactive notebook

Open alexanderjshall opened this issue 2 years ago • 1 comments

Describe the bug

👋 Hey there! I'm having a problem installing the System.Threading.Tasks.Dataflow library from within a Polyglot notebook. No message is produced on the initial message and all references to the package in subsequent code blocks lead to are you missing an assembly reference? errors (including the using statement itself)

My understanding from this issue is that the library is "a framework assembly and is preloaded by the interactive session". Is it possible to either:

  • Import the framework assembly?
  • Have the UI produce a meaningful message if the package fails to import?

Detail in screenshots below - Thanks in advance for the help!

Please complete the following:

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ): image .NET version 8.0.100

  • OS
    • [x] Windows 11
  • Frontend
    • [x] Visual Studio Code

Screenshots

If applicable, add screenshots to help explain your problem.

  1. Installing System.Threading.Tasks.Dataflow (in first code block) does not show as installed but does not fail execution. image

  2. Given the following code block after the install codeblock

#r "nuget: Throw"

using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using Throw;

public record FastParallelForEachSettings(int EnumerationDegreeOfParallelism, int ActionDegreeOfParallelism);

async Task FastForEachAsync<TIn>(
    IAsyncEnumerable<TIn> asyncEnumerable,
    Func<TIn, Task> action,
    int degreeOfParallelismForProcessing,
    CancellationToken cancellationToken
)
{
    degreeOfParallelismForProcessing.Throw("Degree of parallelism must be greater than 0").IfLessThan(1);
    var actionBlock = new ActionBlock<TIn>(
        action,
        new ExecutionDataflowBlockOptions()
        {
            CancellationToken = cancellationToken,
            MaxDegreeOfParallelism = degreeOfParallelismForProcessing
        }
    );
    await foreach (var item in asyncEnumerable.WithCancellation(cancellationToken))
    {
        actionBlock.Post(item);
    }
    actionBlock.Complete();
    await actionBlock.Completion.WaitAsync(cancellationToken);
}

Output: image

alexanderjshall avatar Dec 15 '23 13:12 alexanderjshall

Did you try it without the nuget: prefix?

#r "System.Threading.Tasks.Dataflow"

I was facing a similar issue with using System.ComponentModel.DataAnnotations and #r "System.ComponentModel.Annotations" did the trick.

The docs say:

In C# Interactive, the #r compiler directive adds a reference to a specified assembly, e.g. #r "/path/to/a.dll", or system assembly, e.g. #r "System.Net.Http.Json.dll".

gbd3-en avatar Jan 02 '24 21:01 gbd3-en