JordanMarr / ReactiveElmish.Avalonia

Static Avalonia views for Elmish programs
Other
92 stars 8 forks source link

Pub-sub messaging/subscriptions don't work if you're using Avalonia 11.0.0-rc1.1 with Elmish.Avalonia 1.0.0-alpha-3 #12

Closed moonshxne closed 1 year ago

moonshxne commented 1 year ago

Because 1.0.0-alpha-3 uses Avalonia 11.0.0-preview5, there might've been some messy interface breakage with Avalonia's Dispatch class. When a message bus subscription is dispatched directly, like in AvaloniaExample's MainViewModel.fs, it fails with

System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task Avalonia.Threading.Dispatcher.InvokeAsync(System.Action, Avalonia.Threading.DispatcherPriority)'.
    at Elmish.Avalonia.AvaloniaProgram.cmdDispatch@104-1.Invoke(msg msg)

(or, as in AvaloniaExample's MainViewModel.fs, simply fails to dispatch the Msg, since Cmd.OfFunc.perform "swallows" the exception)

This was the case with my program on Windows 11. I also tested this with the provided AvaloniaExample. Messaging works perfectly fine when you directly reference the most recent commit to Elmish.Avalonia that uses Avalonia 11.0.0-rc1.1, but if you use 1.0.0-alpha-3 from Nuget instead, the Ok buttons don't work.

Even though the corresponding library code hasn't changed since 1.0.0-alpha-3, I think in between Avalonia changed the API to return DispatcherOperation. So even though the library code actually |> ignores the return value, it still fails because the returned type is different? (I'm very new to the whole dotnet ecosystem and I'm actually not the most clear on how ABIs work, so I don't actually know what's quite going on.)

Therefore, I would highly recommend publishing a new version of this library that just references Avalonia 11.0.0-rc1.1; there are so many breaking changes with the 11 series of that library anyway.

P.S. This library (and F#) are so lovely to use/get started with! I'm very new to F#, but the libraries and the language have all been simple to get started with and quite elegantly designed. The language really does strike a really nice balance between pragmatic usability/"getting things done" and the ergonomics/correctness of (usually) immutability-first FP languages 💙.

JordanMarr commented 1 year ago

The library was recently updated to use Avalonia 11.0.0-rc1.1 and the message bus example seems to be working fine for me. I have pushed a new version to NuGet: v1.0.0-alpha-3

moonshxne commented 1 year ago

Publishing a new version to NuGet is exactly what I wanted! Thanks 👍🏼