dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.82k stars 773 forks source link

Can't Use Library From F# (FS1109 System.Drawing) #17295

Closed EricM81 closed 3 weeks ago

EricM81 commented 3 weeks ago

RhinoCommon is transitioning from the .Net Framework to .Net Core. .Net Core is required for cross platform support. This works fine in C#, but won't work from F#.

Repro steps (https://github.com/EricM81/RhinoCommonFsBug):

1) Create a .Net Core 7 library in F#.

2) Add nuget package package: <PackageReference Include="RhinoCommon" Version="8.7.24138.15431" />

3) Inherit the PlugIn class:

open Rhino.PlugIns
type MyPlugin() as this = 
    inherit PlugIn()

3) Compiler complains with "FS1109"

4) Do the same steps in c#. Compiles with no issues.

kerams commented 3 weeks ago

RhinoCommon is transitioning from the .Net Framework to .Net Core

You say that, but it still only supports net48.

This works fine in C#

It compiles, but I'm willing to bet that you'll get a run-time exception if you try to do anything. System.Drawing.Bitmap appears to live in a different assembly on new versions of .NET.

Compilation error is the more reasonable outcome here in my opinion. If anything, C# is being too liberal in what it compiles. I know that oftentimes an old Framework library will just work, but the following warning is displayed for a reason

CsPlugin.csproj : warning NU1701: Package 'RhinoCommon 8.7.24138.15431' was restored using '.NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.

I wouldn't be surprised if the F#'s [team's] policy was to simply consider this an unsupported scenario.

EricM81 commented 3 weeks ago

It compiles, but I'm willing to bet that you'll get a run-time exception if you try to do anything. System.Drawing.Bitmap appears to live in a different assembly on new versions of .NET.

I get that it looks weird, I don't know how or why they are doing this, but people are using this package to create cross-platform Win/Mac plugins on .Net Core with C#. It's only F# that can't compile.

https://developer.rhino3d.com/guides/rhinocommon/moving-to-dotnet-7/

KevinRansom commented 3 weeks ago

@EricM81 -

The coreclr does not support desktop framework assemblies. As soon as you do significant work you will encounter missingmethod exceptions and typeload errors.

The runtime has some libraries for winforms workloads that run on the coreclr, you should port your baselibrary to that framework first. We haven't done any real work to ensure they are supported either, we are rather few developers, however we will certainly try to work with you to ensure that F# works well in that scenario moving forward.

BTW: the error failing your compile was not caused by but because F# doesn't allow you to assign null to bindings holding F# types by default. C# code allows the assignment of null to variables that are typed as reference types.

    c:\kevinransom\RhinoCommonFsBug\FsPlugin\PluginInfo.fs(12,21): error FS0001: The type 'MyPlugin' does not have 'null' as a proper value. See also c:\kevinransom\RhinoCommonFsBug\FsPlugin\PluginInfo.fs(9,34)-(9,38).
  CsPlugin succeeded with 2 warning(s) (1.9s) → CsPlugin\bin\Debug\net7.0\CsPlugin.dll

Kevin

KevinRansom commented 3 weeks ago

Closing this as "by design".