jonsequitur / dotnet-repl

A polyglot REPL built on .NET Interactive
MIT License
730 stars 36 forks source link

--run with #!import file containing #r nuget no longer works #92

Closed marckruzik closed 11 months ago

marckruzik commented 11 months ago

I have a file main.dib (just one cell).

#!import "library.dib"

I have a library.dib file, which requests a nuget (just one cell).

#r "nuget: SSH.NET, 2020.0.2"

I run the following command:

dotnet repl --run main.dib --exit-after-run --output-path output.ipynb

On the same machine (test done with switching back and forth):

Here is the content of output.ipynb with the error:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_repl_cellExecutionStartTime": "2023-11-08T15:31:26.7896059+01:00",
    "dotnet_repl_cellExecutionEndTime": "2023-11-08T15:31:29.0612544+01:00",
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div></div><div><strong>Installing Packages</strong><ul><li><span>SSH.NET</span></li></ul></div><div></div></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>SSH.NET, 2020.0.2</span></li></ul></div></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "ename": "Error",
     "evalue": "System.Collections.Generic.KeyNotFoundException: The given key 'SubmitCode: #r \"nuget: SSH.NET, 2020.0.2\"' was not present in the dictionary.\r\n   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(TKey key)\r\n   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)\r\n   at Microsoft.DotNet.Interactive.KernelInvocationContext.ResultFor(KernelCommand command)\r\n   at Microsoft.DotNet.Interactive.Kernel.SendAsync(KernelCommand command, CancellationToken cancellationToken)\r\n   at Microsoft.DotNet.Interactive.KernelExtensions.LoadAndRunInteractiveDocument(Kernel kernel, FileInfo file)\r\n   at Microsoft.DotNet.Interactive.KernelExtensions.<>c__DisplayClass4_0`1.<<UseImportMagicCommand>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)\r\n   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<AddMiddleware>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at System.CommandLine.Invocation.InvocationPipeline.<InvokeAsync>g__FullInvocationChainAsync|2_0(InvocationContext context)\r\n   at System.CommandLine.Parsing.ParseResultExtensions.InvokeAsync(ParseResult parseResult, IConsole console)\r\n   at Microsoft.DotNet.Interactive.Commands.DirectiveCommand.InvokeAsync(KernelInvocationContext context)\r\n   at Microsoft.DotNet.Interactive.Kernel.HandleAsync(KernelCommand command, KernelInvocationContext context)\r\n   at Microsoft.DotNet.Interactive.KernelCommandPipeline.<BuildPipeline>b__6_0(KernelCommand command, KernelInvocationContext context, KernelPipelineContinuation _)\r\n   at Microsoft.DotNet.Interactive.KernelCommandPipeline.SendAsync(KernelCommand command, KernelInvocationContext context)",
     "output_type": "error",
     "traceback": [
      "   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(TKey key)",
      "   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)",
      "   at Microsoft.DotNet.Interactive.KernelInvocationContext.ResultFor(KernelCommand command)",
      "   at Microsoft.DotNet.Interactive.Kernel.SendAsync(KernelCommand command, CancellationToken cancellationToken)",
      "   at Microsoft.DotNet.Interactive.KernelExtensions.LoadAndRunInteractiveDocument(Kernel kernel, FileInfo file)",
      "   at Microsoft.DotNet.Interactive.KernelExtensions.<>c__DisplayClass4_0`1.<<UseImportMagicCommand>b__0>d.MoveNext()",
      "--- End of stack trace from previous location ---",
      "   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)",
      "   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()",
      "--- End of stack trace from previous location ---",
      "   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<AddMiddleware>b__0>d.MoveNext()",
      "--- End of stack trace from previous location ---",
      "   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()",
      "--- End of stack trace from previous location ---",
      "   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()",
      "--- End of stack trace from previous location ---",
      "   at System.CommandLine.Invocation.InvocationPipeline.<InvokeAsync>g__FullInvocationChainAsync|2_0(InvocationContext context)",
      "   at System.CommandLine.Parsing.ParseResultExtensions.InvokeAsync(ParseResult parseResult, IConsole console)",
      "   at Microsoft.DotNet.Interactive.Commands.DirectiveCommand.InvokeAsync(KernelInvocationContext context)",
      "   at Microsoft.DotNet.Interactive.Kernel.HandleAsync(KernelCommand command, KernelInvocationContext context)",
      "   at Microsoft.DotNet.Interactive.KernelCommandPipeline.<BuildPipeline>b__6_0(KernelCommand command, KernelInvocationContext context, KernelPipelineContinuation _)",
      "   at Microsoft.DotNet.Interactive.KernelCommandPipeline.SendAsync(KernelCommand command, KernelInvocationContext context)"
     ]
    }
   ],
   "source": [
    "#!import \"library-test.dib\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "file_extension": ".cs",
   "mimetype": "text/x-csharp",
   "name": "C#",
   "pygments_lexer": "csharp",
   "version": "10.0"
  },
  "polyglot_notebook": {
   "defaultKernelName": "csharp",
   "items": [
    {
     "name": "csharp"
    }
   ]
  },
  "dotnet_interactive": {
   "defaultKernelName": "csharp",
   "items": [
    {
     "name": "csharp"
    }
   ]
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

I tried with several nugets: same bug.

marckruzik commented 11 months ago

I updated to v0.1.208 and it's now working. I'm really glad. Thank you @jonsequitur.

jonsequitur commented 11 months ago

Thanks for reporting the issue!