interactive icon indicating copy to clipboard operation
interactive copied to clipboard

Error CS0006: Metadata file 'nuget: <...>' could not be found when loading a C# script (*.csx) referencing nuget package

Open Oblomoff opened this issue 2 years ago • 3 comments

Description

  • I have a notebook file (*.ipynb or *.dib)
  • I have a C# script file (*.csx) referencing nuget package
  • The notebook loads that file
  • I get an error CS0006: Metadata file 'nuget: <...>' could not be found"

F# scripts are loaded fine

Example

See example project: NotebooksBug.zip

script.csx

#r "nuget: MathNet.Numerics, 5.0.0"
using System;
string Hello() => "Hello from C# script!";

notebook.ipynb

#r "nuget: MathNet.Numerics, 5.0.0"
#load "script.csx"
Hello()
c:\Users\...\NotebooksBug\script.csx(1,1): error CS0006: Metadata file 'nuget: MathNet.Numerics, 5.0.0' could not be found

.NET Interactive

  • Version: 1.0.355206+4dcedd96b3252430822b3cf1591e7f4031b0df56
  • Library version: 1.0.0-beta.22552.6+4dcedd96b3252430822b3cf1591e7f4031b0df56
  • Build date: 2022-11-03T04:46:59.8757048Z

Environment

  • OS: Windows 11
  • Browser: Edge
  • Frontend: Visual Studio Code

Oblomoff avatar Nov 04 '22 06:11 Oblomoff

This is a subtle difference between the C# Script, F# Script, and notebook dialect. F# directly allows "#r "nuget:...", as does the notebook, but from a pure .csx viewpoint, that's not allowed as a part of the language.

#load ... isn't handled by .NET Interactive, it's instead passed directly to C# as a compiler directive.

If the gesture was instead #!import ... this should work as is.

brettfo avatar Nov 08 '22 18:11 brettfo

So... how do you work around this? I installed .NET 8 SDK and VS Code in a fresh windows 11 sandbox and get this error.

image

ronnieoverby avatar Apr 20 '24 13:04 ronnieoverby

It looks like you have a space before the #r line. Removing that space should solve it.

jonsequitur avatar Jun 10 '24 23:06 jonsequitur