Skip to content

Extension scripts fail when imported from F# context (or written in F# and imported from C# context) #1808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cyberillithid opened this issue Dec 4, 2021 · 1 comment
Labels
Area-F# Specific to F# Area-Packages and Extensions Related to acquiring and using packages and extensions bug Something isn't working Impact-Medium

Comments

@cyberillithid
Copy link

cyberillithid commented Dec 4, 2021

Preface: I recently got inspired to try F# again when I learned that this tool exists (and overall I guess you're doing a great job). Thus I am sorry if I use the terminology I haven't grokked yet incorrectly, or even if some things I expect to work are actually incongruent with the tool as it is now.

Bug description

Referencing packages with extension scripts from F# context execution block

What I expected: If you reference an assembly (i.e., NuGet package of the RandomNumber extension from dotnet/interactive samples/extension/RandomNumber) with extension script from an F# context execution block, #r succeds and extension scripts works normally.
What I got: The namespaces are inaccessible whether the extension script is written in F# or C#. (In the RandomNumber example you get CS0246 for "types/namespaces" RandomNumberExtension and RandomNumberGenerator, and so no commands are registered.

Referencing packages with F# extension scripts from C# context execution block

What I expected: You can use the magic commands written in F# when working from C# mode.
What I got: DotNet (in Microsoft.DotNet.Interactive) and thus KernelInvocationContext are inaccessible from the F# script invoked from running #r in C#-mode, which thus fails to typecheck.

Steps to reproduce

With a NuGet-available package

The only one I found is Interactive.Journey from this same repo.
So, the minimal reproduction of the bug is to run:

#!fsharp
#r "nuget:Microsoft.DotNet.Interactive.Journey,1.0.0-beta.21602.1"

which fails with CS0234, as demonstrated on the picture attached
While the same #r command in #!csharp mode executes the extension script successfully.

Other reproductions

The same behaviour can be observed (and debugged a bit more easily) with the RandomNumber extension from dotnet/interactive samples/extension/RandomNumber.

If you add the following to the beginning of the extension.dib of the RandomNumber extension:

!fsharp
open Microsoft.DotNet.Interactive
open RandomNumberExtension

and try to import the RandomNumber package from either F# or C# contexts, F# invocation will fail with F# typecheck error around RandomNumberExtension, while C# invocation will fail with F# typecheck error around DotNet.

Environment info

Windows 10:

  • .NET Interactive: versions 1.0.260201 through 1.0.235701 (at first I suspected the issue was introduced somewhere along the way)
  • Frontend: Jupyter, VS Code, VS Code Insiders

Binder: started from link from the docs/NotebooksOnBinder.md

Things that look tangentially relevant

Issue #1307
Also probably the fact about split of C# and F# kernels, as described in variable-sharing.md

Since I performed most of the experiments locally, not to clutter screenshots with non-English compiler output, the only picture attached is the reproduction in Binder.
image

@WhiteBlackGoose
Copy link
Contributor

Another repro.

Consumer.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <None Include="extension.dib" Pack="true" PackagePath="interactive-extensions/dotnet" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="AngouriMath" Version="1.3.0" />
  </ItemGroup>

</Project>

Class1.cs:

namespace Consumer;

public class Foo
{
    public void Method2() => Console.WriteLine(AngouriMath.MathS.FromString("1 + 1"));
}

(Class1.cs is needed to verify that the dep is correct)

Extension.dib:

#!csharp

using AngouriMath;

Console.WriteLine("Hello, world");
Console.WriteLine(AngouriMath.MathS.FromString("sqrt(s)").Latexise());

To pack, I do

rm -r ~/.nuget/packages/consumer
dotnet pack -c release -p:Version=10.0.0

Now, this notebook cell:

#i "/main/tmp/repro/cs2cs/Consumer/bin/release"
#r "nuget:Consumer"

(of course replace the path to yours)

C# context
image

F# context
image

WhiteBlackGoose added a commit to asc-community/AngouriMath that referenced this issue Jul 12, 2022
Now loading AngouriMath without interactive package should still give
interactive experience with LaTeX visualization of formulas.

dib file is packed along with the dlls into AngouriMath package. But
we have to make sure it doesn't leak into its dependents, because due
to a bug dotnet/interactive#1808, neither F# dibs nor C# dibs called
from F# interactive context don't work (assemblies are not available, it
will complain about "AngouriMath" not existing in the current context).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-F# Specific to F# Area-Packages and Extensions Related to acquiring and using packages and extensions bug Something isn't working Impact-Medium
Projects
None yet
Development

No branches or pull requests

3 participants