hawkerm / monaco-editor-uwp

A Windows Runtime Component wrapper around the web-based Monaco Editor.
MIT License
153 stars 36 forks source link

Cannot change certain Editor.Options when the TestApp is compiled with .NET Native toolchain #49

Closed WelterDevelopment closed 2 years ago

WelterDevelopment commented 4 years ago

Steps to reproduce:

  1. Add a toggle button to the ItemsControl in MainPage.xaml in the TestApp:
    <Button Content="Line Numbers" Click="Numbers_Click" />
  2. Add the click event handler to MainPage.xaml.cs:
    private void Numbers_Click(object sender, RoutedEventArgs e)
    {
    options.LineNumbers = options.LineNumbers == LineNumbersType.On ? LineNumbersType.Off : LineNumbersType.On;
    }
  3. Run the TestApp without compiling with the .NET Native toolchain. Clicking the button a few times will toggle the line numbers on and off as expected.
  4. Run the TestApp with compiling with the .NET Native toolchain. Now you see that reenabling the line numbers will not work, so they disappeared permanently.

This issue also occurs e.g. with Editor.Options.WordWrap and maybe even for more Editor.Options. I have not tested them all. And turning off the .NET Native Compiler is of course not an option since all UWP apps you want to submit to the Microsoft Store need to be compiled with this toolchain.

WelterDevelopment commented 4 years ago

There is some rd.xml madness going on and I could not find any clue in the documentation on how to solve this. <Namespace Name="Monaco.Editor" Serialize="All" Dynamic="All"/> does not seem to work with JsonConverters (like LineNumbersTypeConverter). A quick workaround for me was to reset the LineNumbers Property back to the old string type in IEditorOptions:

 [JsonProperty("lineNumbers", NullValueHandling = NullValueHandling.Ignore)]
 string LineNumbers { get; set; }
hawkerm commented 4 years ago

Thanks for digging in and finding the cause @WelterDevelopment. There may be some rd.xml stuff we can do in the component, I'll have to take a look.

hawkerm commented 2 years ago

I've added toggling this option in the sample app. I can see what you see in Release mode that it's updating on the C# side, but then just being turned off in the Monaco editor (and never turning back on); even though it's fine in Debug.

It's fine up until the point of serialization. I'm going to try debugging on the script side now to see what might be going on there on the receiving end to confirm.

hawkerm commented 2 years ago

Ok, from the script side it's still getting called to update, but in Debug it's getting passed the string value like "on", "off", "relative", etc... In Release mode it's being passed an int like 0, 1, 2 instead... 🤔

hawkerm commented 2 years ago

For whatever reason it seems like Json.NET can't infer the JsonTypeConverter defined from the interface itself. If I declare the converter on the property, it works fine... No idea why. For now will just declare on property as well as that should resolve the issue.