Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono Bug: Error message when attempting to observe a newly assigned value after mutating an object member

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

enter image description here 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
like image 939
Scott Nimrod Avatar asked Jun 25 '20 19:06

Scott Nimrod


1 Answers

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.

like image 117
Tomas Petricek Avatar answered Sep 30 '22 04:09

Tomas Petricek