Skip to content

Nuget #r references do not resolve assemblies referenced through the primary one #9217

@jbeeko

Description

@jbeeko

Nuget #r references, for example r# "nuget: FParsec" do not add the directory containing the primary assembly to the assembly search path. This means assemblies referenced thought the outer assembly will not be found by default.

Reviewing the RFC it is not clear to me if this directory should automatically be added. But the announcement here https://devblogs.microsoft.com/dotnet/announcing-f-5-preview-1/, indicates the features should work like a package reference in a project file.

This will download and install the latest JSON.NET package (if it’s not in your package cache), resolve all dependencies, and let you use the library as if it were in a fully-fledged project.

In the case of a package reference via a .fsproj file assemblies referenced thought the primary .dll are automatically found so it sees that should be the case for #r nuget: references as. well.

Repro steps

To demonstrate the issue save the below snipped as Test.fsx and run it with the F# 5.0 FSI using:
dotnet fsi --langversion:preview Script.fsx.

#r "nuget: Newtonsoft.Json"
#r "nuget: FParsec"


// #I "/Users/joergbeekmann/.nuget/packages/fparsec/1.1.1/lib/netstandard2.0"
// Without an #I directive which adds the appropriate director the search path addtional dll's r
// referenced through another can't be found. Instead the following error is generated: 
//
// .../Test.fsx(25,11): error FS0074: The type referenced through 'FParsec.CharStream`1' is
// defined in an assembly that is not referenced. You must add a reference to assembly 'FParsecCS'.
//
// This is not neccessary when adding a package via a .fsproj file. 

open Newtonsoft.Json
open FParsec


let o = {| X = 2; Y = "Hello" |}
printfn "%s" (JsonConvert.SerializeObject o)


let test p str =
    match run p str with
    | Success(result, _, _)   -> printfn "Success: %A" result
    | Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg
test pfloat "1.234"

Expected behavior

The script should succeed with the following output:
image

Actual behavior

It will fail as follows:
image

Known workarounds

Add a #I directive that adds the directory containing the main .dll to the search path. In this case:

#I "/Users/joergbeekmann/.nuget/packages/fparsec/1.1.1/lib/netstandard2.0"

Related information

Provide any related information (optional):

  • MacOs
  • .NET 5.0.100-preview.3.20216.6

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions