Skip to content
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

Error using System.Drawing.Common with FSI #12023

Open
tarekgh opened this issue Aug 24, 2021 · 11 comments
Open

Error using System.Drawing.Common with FSI #12023

tarekgh opened this issue Aug 24, 2021 · 11 comments
Labels
Area-FSI Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@tarekgh
Copy link
Member

tarekgh commented Aug 24, 2021


Issue moved from dotnet/runtime#57922


From @auslavs on Monday, August 23, 2021 8:01:05 AM

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

@tarekgh
Copy link
Member Author

tarekgh commented Aug 24, 2021


Issue moved from dotnet/runtime#57922

  • Please respond to @msftbot[bot].

From @msftbot[bot] on Monday, August 23, 2021 8:01:09 AM

Tagging subscribers to this area: @safern, @tarekgh
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: auslavs
Assignees: -
Labels:

area-System.Drawing, untriaged

Milestone: -

@tarekgh
Copy link
Member Author

tarekgh commented Aug 24, 2021


Issue moved from dotnet/runtime#57922


From @tarekgh on Monday, August 23, 2021 4:20:20 PM

@ericstj any thoughts what can cause that?

@tarekgh
Copy link
Member Author

tarekgh commented Aug 24, 2021


Issue moved from dotnet/runtime#57922


From @ericstj on Monday, August 23, 2021 4:42:10 PM

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

@tarekgh
Copy link
Member Author

tarekgh commented Aug 24, 2021


Issue moved from dotnet/runtime#57922

  • Please respond to @am11.

From @am11 on Monday, August 23, 2021 4:46:31 PM

Yup, dotnet fsi with #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

// Generated from #r "nuget:Package References"
// ============================================
//
// DOTNET_HOST_PATH:(C:\Program Files\dotnet\dotnet.exe)
// MSBuildSDKsPath:(C:\Program Files\dotnet\sdk\3.1.200-preview-014883\Sdks)
// MSBuildExtensionsPath:(C:\Program Files\dotnet\sdk\3.1.200-preview-014883\)
//
// References
//
#r @"/Users/am11/.nuget/packages/microsoft.win32.systemevents/5.0.0/lib/netstandard2.0/Microsoft.Win32.SystemEvents.dll"
#r @"/Users/am11/.nuget/packages/system.drawing.common/5.0.2/runtimes/unix/lib/netcoreapp3.0/System.Drawing.Common.dll"

(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)

...

@tarekgh
Copy link
Member Author

tarekgh commented Aug 24, 2021


Issue moved from dotnet/runtime#57922


From @ericstj on Tuesday, August 24, 2021 12:36:40 AM

netcoreapp3.0 is "better" than netstandard2.0 for a net5.0 project. See https://nugettools.azurewebsites.net/5.11.0/framework-precedence?framework=net5.0&exludedIdentifiers=

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.

This issue should be transferred to https://github.com/dotnet/fsharp. @KevinRansom @TIHan @cartermp can you help with that?

@KevinRansom KevinRansom added the Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. label Sep 22, 2021
@Happypig375
Copy link
Member

Bump

@dsyme
Copy link
Contributor

dsyme commented Mar 31, 2022

I'm still getting this on .NET 6

C:\GitHub\dsyme\fsharp>artifacts\bin\fsi\Debug\net6.0\fsi.exe

Microsoft (R) F# Interactive version 12.0.0.0 for F# 6.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> #r "nuget: System.Drawing.Common"
-
- 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
- ;;
[Loading C:\Users\donsy\AppData\Local\Temp\43480--61af721a-f468-4be8-907f-412c233af999\Project.fsproj.fsx]
namespace FSI_0002.Project

Binding session to 'C:/Users/donsy/.nuget/packages/system.drawing.common/6.0.0/runtimes/win/lib/net6.0/System.Drawing.Common.dll'...


error FS0193: Could not load file or assembly 'System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at <StartupCode$FSI_0003>.$FSI_0003.main@()
Stopped due to error
>

@KevinRansom
Copy link
Member

KevinRansom commented Mar 31, 2022

I will take a look shortly. Pretty sure it's not a setup issue.

@KevinRansom
Copy link
Member

System.Drawing.Common is not a standard: Microsoft.NETCore.App assembly.
It is in fact a : Microsoft.WindowsDesktop.App assembly

We don't probe there and fsi is not compiled: Microsoft.WindowsDesktop.App. So the runtime doesn't know to probe there either.

I'm not sure what to do about this. We haven't really considered the impact of Microsoft.WindowsDesktop.App or Microsoft.AspNetCore.App on fsi or fsc for that matter.

I imagine that we can probably do some stuff within #r "nuget: to allow the specification of these" framework extensions.

@KevinRansom
Copy link
Member

Here is another example: #13473

@KevinRansom
Copy link
Member

Okay, I think we may be able to do it using #r nuget: ... it's going to take some work though.

Nuget has packages with binaries, which look like they may work ...

If we do it right, I might be able to eliminate the preloading hack we do today although maybe not because of namespaces.

Prioritization remains to be seen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FSI Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Status: New
Development

No branches or pull requests

5 participants