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

Win7, VSCode, F# Interactive. Could not load file or assembly 'System.Windows.Forms.DataVisualization" #150

Open
BogusAltay opened this issue Jan 29, 2022 · 7 comments

Comments

@BogusAltay
Copy link

Hello, All!

As far as I understand, System.Windows.Forms.DataVisualization is a system assembly. You don't need to explicitly refer to it. Why FSharp.Charting can't find an assembly? See attachment.
What am I doing wrong?

Err

@Hydraxize
Copy link

Do we have an update on this error? FSharp.Charting is unusable in interactive at the moment. I've tried to load the missing dll with this input at the start of the program:
#I @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\"
The interactive console will show the binding:
Binding session to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.DataVisualization.dll'...
But the error remains the same. Reference to any other assembly versions didn't solve the issue. Can we have a link to the System.Windows.Forms.DataVisualization.dll we need to refer to?

@dsyme
Copy link
Member

dsyme commented Mar 16, 2022

You're running F# Interactive for .net core. You will need to use .net framework. I believe only Visual Studio has a legacy switch for running fsi for .net framework from the IDE.

You can run it from the command line using "fsi" from a vs2022 developer prompt.

I don't know if System.Windows.Forms.DataVisualization.dll is available for netcoreapp/net5/6, if it is we could add support for that

@dsyme
Copy link
Member

dsyme commented Mar 16, 2022

Looks like it's all considered deprecated for netcore, unless someone else is maintaining a fork.

https://github.com/dotnet/winforms-datavisualization

Still there is a partial nuget available. Perhaps it's enough to use in practice

@Hydraxize
Copy link

Thanks @dsyme, the fsi command in vs2022 developer prompt is doing the job. I'll let the Interactive programming aside for now.

@nightroman
Copy link

FWIW, I am able to use the copy of FSharp.Charting.fs with https://github.com/dotnet/winforms-datavisualization in net6.0 scripting with FSharp.Compiler.Service. I had to comment out the context menu code (to be continued). But overall it all works well.

@nightroman
Copy link

The menu issue is solved - in net core apps ContextMenuStrip is used instead of ContextMenu.

              let menu = new ContextMenuStrip()
              let dlg = new SaveFileDialog(Filter = "PNG (*.png)|*.png|Bitmap (*.bmp;*.dib)|*.bmp;*.dib|GIF (*.gif)|*.gif|TIFF (*.tiff;*.tif)|*.tiff;*.tif|EMF (*.emf)|*.emf|JPEG (*.jpeg;*.jpg;*.jpe)|*.jpeg;*.jpg;*.jpe|EMF+ (*.emf)|*.emf|EMF+Dual (*.emf)|*.emf")
              let miCopy = new ToolStripMenuItem("&Copy Image to Clipboard", ShortcutKeys = (Keys.Control ||| Keys.C))
              let miCopyEmf = new ToolStripMenuItem("Copy Image to Clipboard as &EMF", ShortcutKeys = (Keys.Control ||| Keys.Shift ||| Keys.C))
              let miSave = new ToolStripMenuItem("&Save Image As..", ShortcutKeys = (Keys.Control ||| Keys.S))
              let miEdit = new ToolStripMenuItem("Show Property &Grid", ShortcutKeys = (Keys.Control ||| Keys.G))

              miEdit.Click.Add(fun _ -> 
                  miEdit.Checked <- not miEdit.Checked
                  props.Visible <- miEdit.Checked)

              miCopy.Click.Add(fun _ ->        
                  srcChart.CopyChartToClipboard())

              miCopyEmf.Click.Add(fun _ ->
                  srcChart.CopyChartToClipboardEmf(self))

              miSave.Click.Add(fun _ ->
                  if dlg.ShowDialog() = DialogResult.OK then
                      let fmt = 
                          match dlg.FilterIndex with
                          | 1 -> ChartImageFormat.Png
                          | 2 -> ChartImageFormat.Bmp
                          | 3 -> ChartImageFormat.Gif
                          | 4 -> ChartImageFormat.Tiff
                          | 5 -> ChartImageFormat.Emf
                          | 6 -> ChartImageFormat.Jpeg
                          | 7 -> ChartImageFormat.EmfPlus
                          | 8 -> ChartImageFormat.EmfDual
                          | _ -> ChartImageFormat.Png
                      chart.SaveImage(dlg.FileName, fmt  |> int |> enum) )

              menu.Items.Add(miCopy) |> ignore
              menu.Items.Add(miCopyEmf) |> ignore
              menu.Items.Add(miSave) |> ignore
              menu.Items.Add(miEdit) |> ignore
              self.ContextMenuStrip <- menu

@general-rishkin
Copy link

general-rishkin commented Aug 10, 2023

It seems this issue is still ongoing. I just got the following error with Foo.fsx:

Binding session to 'C:/Users/.nuget/packages/fsharp.charting/2.1.0/lib/net45/FSharp.Charting.dll'...
System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'System.Windows.Forms.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at <StartupCode$FSI_0003>.$FSI_0003.main@()
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Stopped due to error

With Foo.dib, I get:

Error: input.fsx (20,1)-(20,21) typecheck error The type referenced through 'System.Windows.Forms.DataVisualization.Charting.AxisEnabled' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows.Forms.DataVisualization'.

This was from the following piece of code both in "foo.dib" and "foo.fsx" on Windows.

#r "nuget: FSharp.Charting"
open FSharp.Charting   \\---> Main culprit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants