Closed Jand42 closed 6 years ago
This occurs for me even with F# 3.1.2 and .NET 4.5, using the following Warp app (with an extra ChartJs dependency):
open WebSharper
[<Client>]
module Client =
open WebSharper.JavaScript
open WebSharper.Html.Client
open WebSharper.ChartJs
let Main () =
let n = ref 10
let Push (chart : Chart.LineChart) (value : float) =
chart.RemoveData()
chart.AddData([| float value |], string (!n + 1))
n := !n + 1
let initialData =
[| for x in 1 .. !n do
yield (string x, Math.Random()) |]
let chart : Chart.LineChart option ref = ref None
Div [
Canvas [
Width "1200"
Height "400"
]
|>! OnAfterRender (fun canvas ->
let canvas = As<CanvasElement> canvas
let (labels, dataset) =
Array.unzip initialData
let data =
LineChartData(
Labels = labels,
Datasets = [| LineChartDataset(Data = dataset) |]
)
Chart.Defaults.ShowTooltips <- false
let options =
LineChartConfiguration(
BezierCurve = false,
DatasetFill = false
)
chart := Some <| Chart(canvas.GetContext "2d").Line(data, options)
)
Div [
Button [ Text "Push" ]
|>! OnClick (fun _ _ ->
Push (!chart).Value <| Math.Random()
)
]
]
open WebSharper.Html.Server
let MyApp =
Warp.CreateSPA (fun ctx ->
[Div [ClientSide <@ Client.Main() @>]]
)
[<EntryPoint>]
Warp.RunAndWaitForInput(MyApp) |> ignore
When I move the local functions in main
to toplevel, I get:
System.TypeLoadException: Method 'GenerateLegend' in type 'LineChart' from assem
bly 'WebSharper.ChartJs, Version=3.2.0.0, Culture=neutral, PublicKeyToken=dcd983
dec8f76a71' does not have an implementation.```
(Just to be sure, this is the code for the previous comment:
open WebSharper
open WebSharper.JavaScript
open WebSharper.Html.Client
open WebSharper.ChartJs
[<JavaScript>]
let n = ref 10
[<JavaScript>]
let chart : Chart.LineChart option ref = ref None
[<JavaScript>]
let Push (value : float) =
(!chart).Value.RemoveData()
(!chart).Value.AddData([| float value |], string (!n + 1))
n := !n + 1
[<JavaScript>]
let DynamicChart () =
let initialData =
[| for x in 1 .. !n do
yield (string x, Math.Random()) |]
Div [
Canvas [
Width "1200"
Height "400"
]
|>! OnAfterRender (fun canvas ->
let canvas = As<CanvasElement> canvas
let (labels, dataset) = Array.unzip initialData
let data =
LineChartData(
Labels = labels,
Datasets = [| LineChartDataset(Data = dataset) |]
)
Chart.Defaults.ShowTooltips <- false
let options =
LineChartConfiguration(
BezierCurve = false,
DatasetFill = false
)
chart := Some <| Chart(canvas.GetContext "2d").Line(data, options)
)
Div [
Button [ Text "Push" ]
|>! OnClick (fun _ _ ->
Push <| Math.Random()
)
]
]
open WebSharper.Html.Server
let MyApp =
Warp.CreateSPA (fun ctx ->
[Div [ClientSide <@ DynamicChart() @>]]
)
[<EntryPoint>]
Warp.RunAndWaitForInput(MyApp) |> ignore
)
Original F# 4.0 problem still persists. It seems that creating the types metadata for the assembly fails silently, no type lookup information is encoded.
@granicz Your issues here was a result of invalid IL generation by WIG on implementing interfaces (#437). This created a type load error when reflecting with System.Reflection used by WS.Warp (standard WS compilation only uses Mono.Cecil to read metadata).
(Sorry, in both of the above examples, the line
let canvas = As<CanvasElement> canvas
should read
let canvas = As<CanvasElement> canvas.Body
)
I now verified that both examples work with F# 3.1. So we need to get F# 4.0 sorted out.
General comment on "Error in InlineControl": if you encounter it, make sure that the targeted method has JavaScript
attribute
This is now handled properly in WebSharper 4.
Switching a new Client-Server Web Application to .NET 4.5+ and F# 4.0 in VS15 RC fails at runtime with stack trace