I'm observing an error message on a data-tip when attempting to observe a newly assigned value after mutating an object member.
Viewmodel:
I'm trying to mutate the header member of a viewmodel object.
let mutable header : NavBarItem option = None
member x.Header with get() = header
and set(v) = header <- v
base.NotifyPropertyChanged(<@ x.Header @>)
...
//----------------------------------
// THE FOLLOWING ERRORS
//----------------------------------
member x.LoadAsync(panelId:PanelId) =
let items = seq [NavBarItem() :> UITemplate]
let result = items |> Seq.map (fun v -> v :?> NavBarItem)
|> Seq.tryHead // Error recovering value
x.Header <- result
Error:
Here's the error after I hover my cursor over x.Header:
Incorrect number or types of arguments Parameter name: arguments
Here's a bug report that I observed after researching the error message.
UPDATE:
I attempted to serialize the sequence of objects that I did have access to so that I could deserialize the json and access an individual item.
That also failed:
let temp = seq [NavBarItem() :> UITemplate] |> filterToNavBarItems
|> Seq.cast<NavBarItem>
let json = JsonConvert.SerializeObject(temp)
let items = JsonConvert.DeserializeObject<NavBarItem seq>(json)
let item = items |> Seq.tryHead
x.Header <- item // Error recovering value
Json:
[{"MeasureId":"some_navbar_id","Header":"Dashboard","Subheader":"Trauma Alerting","EmblemLabel":"","IsEmblemAttached":false,"EmblemBGColor":"","EmblemFGColor":""}]
Appendix:
type UITemplate =
abstract member ToString : unit -> string
abstract member OrderIndex : int with get, set
type NavBarItem() =
inherit ViewModelBase()
let mutable header = ""
interface UITemplate with
member x.ToString() = "NavBarItem"
member val OrderIndex = -1 with get,set
member x.Header with get() = header
and set(v) = header <- v
base.NotifyPropertyChanged(<@ x.Header @>)
type ViewModelBase () =
let propertyChanged = Event<PropertyChangedEventHandler,PropertyChangedEventArgs>()
let getPropertyName = function
| PropertyGet(_,pi,_) -> pi.Name
| _ -> invalidOp "Expecting property getter expression"
interface INotifyPropertyChanged with
[<CLIEvent>]
member this.PropertyChanged = propertyChanged.Publish
member this.NotifyPropertyChanged propertyName =
propertyChanged.Trigger(this,PropertyChangedEventArgs(propertyName))
member this.NotifyPropertyChanged quotation =
quotation |> getPropertyName |> this.NotifyPropertyChanged
It is hard to answer your question, because the code cannot really be compiled as-is. This makes it hard to see where the error is, because it is likely related to something that is not shown in your snippet.
I tried getting the code to compile by removing as much as possible. I ended up with the following, but this works fine:
type ViewModelBase() =
member x.NotifyPropertyChanged(a:Microsoft.FSharp.Quotations.Expr<'a>) = ()
type NavBarItem() =
inherit ViewModelBase()
let mutable header : NavBarItem option = None
member x.Header
with get() = header
and set(v) =
header <- v
base.NotifyPropertyChanged(<@ x.Header @>)
member x.LoadAsync(panelId:int) = async {
let result = None
x.Header <- result }
If you can extend this minimal sample so that it exhibits the error, then I'm sure people will be able to help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With