'System.Drawing.Bitmap' in assembly 'System.Drawing'

In F# I can’t open the Rhino namespace.

FS1109: A reference to the type 'System.Drawing.Bitmap' in assembly 'System.Drawing' was found, but the type could not be found in that assembly

try

#r "RhinoCommon.dll" 
open Rhino

in Fesh | Food4Rhino in Rh8 or Rh9

Sub-namespaces like Rhino.Geometry work fine.
Adding #r "nuget: System.Drawing.Common" does not help.

GitHub Issue

Is this because Rhino has ist own implementation of System.Drawing?
Since Rh9 is deprecating .Net Framework , could this be fixed there?
@curtisw @CallumSykes

Hi @Goswin,

This from my AI bot - take it for what it’s worth…


The root Rhino namespace contains Rhino.BitmapExtensions, a static class of extension methods on System.Drawing.Bitmap (IsNormalMap, ConvertToNormalMap, BitmapAsTextureFileReference). When F# opens a namespace, it resolves the types of every extension member in it, so open Rhino has to resolve Bitmap. No sub-namespace has an extension class on Bitmap, which is why open Rhino.Geometry and the others work.

The error names assembly System.Drawing, so the RhinoCommon being referenced is most likely the .NET Framework 4.8 build in System\. That build expects Bitmap to be inside System.Drawing.dll. On .NET 8, the System.Drawing.dll in Microsoft.NETCore.App forwards only the primitive types (Color, Point, Size and so on). The copy that forwards Bitmap to System.Drawing.Common is in Microsoft.WindowsDesktop.App. Adding the System.Drawing.Common NuGet package doesn’t change where System.Drawing resolves, so it doesn’t help.

Rhino for Windows also ships a .NET 8 build of RhinoCommon in System\netcore\. That build references Bitmap in System.Drawing.Common directly. Two things to try:

#r @"C:\Program Files\Rhino 8\System\netcore\RhinoCommon.dll"
open Rhino

or, to keep the current RhinoCommon, reference the WindowsDesktop assemblies first:

#r @"C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.x\System.Drawing.dll"
#r @"C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.x\System.Drawing.Common.dll"
#r "RhinoCommon.dll"
open Rhino

(replace 8.0.x with the installed version). For Fesh itself, adding the Microsoft.WindowsDesktop.App reference assemblies to the compiler’s default references on Windows should fix this for every script.

– Dale

Indeed, using Rhinocommon from the /netcore/ path fixed it. I didn’t know Rhino shipped with several versions of it. :flushed_face: Did I miss some documentation? I didn’t find it here: Rhino - Moving to .NET Core