Resolving Plotly.NET and Giraffe Compatibility Issues
I am not blaming anyone for this one. It’s more a post to vent, but I am running into an issue trying to use Plotly.NET within a Giraffe web app.
Plotly.NET is a wrapper for plotly.js, a very popular JavaScript charting library. The wrapper makes it convenient to generate plotly.js charts using F# code and is mostly used in .NET Interactive notebooks, or so is my guess.
Giraffe is “A functional ASP.NET Core micro web framework for building rich web applications”. Basically, it’s a layer on top of ASP.NET core plumbing that is functional first and is widely used in F# ecosystems.
OK, so what’s the problem? Well, I decided to use Plotly.NET in a web app that’s built on top of Giraffe. What’s happening is that both use Giraffe.ViewEngine to render HTML bits. But what the latest Plotly.NET did is reference Giraffe.ViewEngine.StrongName v2.0 while Giraffe framework is referencing Giraffe.ViewEngine v1.4.
When I add Plotly.NET reference to my Giraffe project, I get this “beautiful” error message:
error FS0001: Type mismatch.
Expecting a 'XmlNode -> 'a'
but given a 'XmlNode -> HttpFunc -> 'b -> HttpFuncResult'
The type
'Giraffe.ViewEngine.HtmlElements.XmlNode (Giraffe.ViewEngine.StrongName, Version=2.0.0.0, Culture=neutral, PublicKeyToken=02
8aa8e2a326f4d0)'
does not match the type
'Giraffe.ViewEngine.HtmlElements.XmlNode (Giraffe.ViewEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null)'
At first, I thought maybe I need to upgrade Giraffe libraries, but nope, Giraffe.ViewEngine 1.4 is the latest and greatest. Giraffe.ViewEngine.StrongName seems to have been created as a one-off for those that need strong-named assemblies in their projects, and Plotly.NET appears to be one of them.
Initial solution
Well, I pulled down the Plotly.NET source code and rebuilt it with a Giraffe.ViewEngine 1.4 reference and added the resulting assembly to my Giraffe project. And voila, all is well.
But now I have to maintain this “beautiful” concoction as a library in my source code. I think what Plotly.NET could do is maintain two variants of their released libraries — one with strong naming and one without. But I am not going to pester the maintainer about this, as I am sure they have bigger and greater things on their mind, and I have bigger and greater things than to contribute the work for this idea.
I had to find a better way.
A better solution
I checked out other options I have for charting and XPlot.Plotly library seemed like a good choice. The API is very similar to Plotly.NET, and the library is also written for F# applications, so it feels familiar. It was easy to use it as a replacement with minimal code changes.
I added the reference, adjusted the client code a little bit as in how the chart is informed, rebuilt the solution and all is well in my world again.