You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling System.Drawing.Common within FSharp Interactive, the assembly cannot be loaded
error FS0193: Could not load file or assembly 'System.Drawing.Common, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
Repro fsx script for the error:
#r "nuget: System.Drawing.Common, 5.0.2"
open System.IO
open System.Drawing
let getBitmapWidth =
use stream = new FileStream("image.jpg",FileMode.Open,FileAccess.Read)
use bm = new Bitmap(stream)
bm.Width
FSI version details:
Microsoft (R) F# Interactive version 11.4.2.0 for F# 5.0
(note the netcoreapp3.0 reference).
If we explicitly reference the netstandard2.0 assembly instead, it works fine:
$ dotnet fsi
>#r "/Users/am11/.nuget/packages/system.drawing.common//5.0.2/lib/netstandard2.0/System.Drawing.Common.dll"
- open System.IO
- open System.Drawing
-
- let getBitmapWidth =
- use stream = new FileStream("image.jpg",FileMode.Open,FileAccess.Read)
- use bm = new Bitmap(stream)
- bm.Width;;
--> Referenced '/Users/am11/.nuget/packages/system.drawing.common//5.0.2/lib/netstandard2.0/System.Drawing.Common.dll' (file may be locked by F# Interactive process)
...
So choosing netcoreapp3.0 is correct, you can see that in the project I attached if you restore and examine the assets file you can see what an actual project will resolve. Choosing a runtime asset is dubious for reference, how I can see why this might be correct for interactive since here reference and runtime are the same thing.
That doesn't really explain why fsi couldn't load it though. Your workaround of using ns2.0 is probably just treating the symptom. Something in the runtime loader for fsi isn't consistent with how it's compiling.
Activity
tarekgh commentedon Aug 23, 2021
@ericstj any thoughts what can cause that?
ericstj commentedon Aug 23, 2021
I'm guessing it's an issue with FSI's loader for nuget packages. The package works fine when consumed from an application.
sdc.zip
am11 commentedon Aug 23, 2021
Yup,
dotnet fsiwith#r "nuget: System.Drawing.Common, 5.0.2"seems to be (incorrectly?) picking up netcoreapp3.0, instead of netstandard2.0:file:
/var/folders/lt/lqsrf7fs78d93xwjzhj62bg40000gn/T/nuget/24947--bb21e9ae-ff7d-4b0c-a258-233acaf14353/Project.fsproj.fsx(note the netcoreapp3.0 reference).
If we explicitly reference the netstandard2.0 assembly instead, it works fine:
ericstj commentedon Aug 24, 2021
netcoreapp3.0is "better" thannetstandard2.0for anet5.0project. See https://nugettools.azurewebsites.net/5.11.0/framework-precedence?framework=net5.0&exludedIdentifiers=So choosing
netcoreapp3.0is correct, you can see that in the project I attached if you restore and examine the assets file you can see what an actual project will resolve. Choosing aruntimeasset is dubious for reference, how I can see why this might be correct for interactive since here reference and runtime are the same thing.That doesn't really explain why fsi couldn't load it though. Your workaround of using ns2.0 is probably just treating the symptom. Something in the runtime loader for fsi isn't consistent with how it's compiling.
This issue should be transferred to https://github.com/dotnet/fsharp. @KevinRansom @TIHan @cartermp can you help with that?
tarekgh commentedon Aug 24, 2021
This issue was moved to dotnet/fsharp#12023