Skip to content

InvalidOperationException on Mac: This PlotModel is already in use by some other PlotView control. #139

Closed

Description

@janusw

I have a Xamarin.Forms app that runs well on Android, iOS and UWP. When running on MacOS, however, I get errors when updating the plot (by re-assigning the PlotModel):

  System.InvalidOperationException: This PlotModel is already in use by some other PlotView control.
    at OxyPlot.PlotModel.OxyPlot.IPlotModel.AttachPlotView (OxyPlot.IPlotView plotView) [0x00011] in <aa89ede85c2344f7894022daa95cfaf3>:0
    at OxyPlot.Xamarin.Mac.PlotView.set_Model (OxyPlot.PlotModel value) [0x00027] in <bc79692f004c40a5a09a55685ae301d5>:0
    at OxyPlot.Xamarin.Forms.Platform.MacOS.PlotViewRenderer.OnElementChanged (Xamarin.Forms.Platform.MacOS.ElementChangedEventArgs`1[TElement] e) [0x00029] in <8e51f4d8166f43efa82d9a432db15ebc>:0
    at Xamarin.Forms.Platform.MacOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x0017a] in <6cf85f52b2ba4368b7f5ac91b0fb6d86>:0

This happens both with 2.0.0-beta.1 and 2.0.0-beta.2

Activity

  1. janusw commented on Dec 21, 2022

    @janusw
    MemberAuthor

    I tried to work around it by only modifying the PlotModel instead of assigning a completely new one, but the error still occurs.

  2. VisualMelon commented on Dec 21, 2022

    @VisualMelon

    It indicates the same PlotModel is attached to a second PlotView: can only have one PlotModel per view, and if you want to 'change' view, you need to assign the Model of that view to null or some other PlotModel before assigning the Model of the view to which you want to reassign the PlotModel (so that the PlotModel is informed that it is no longer attached to the old view)

  3. janusw commented on Dec 21, 2022

    @janusw
    MemberAuthor

    It indicates the same PlotModel is attached to a second PlotView

    Well, in fact I'm only using a single PlotView. So either this view is somehow destroyed and re-created under certain conditions, or some other weird thing is going on (as mentioned, the same code works fine on all other platforms). I'll need to look into this a bit deeper, I guess ...

  4. VisualMelon commented on Dec 21, 2022

    @VisualMelon

    I've seen users having issues with virtualisation in the past; maybe there's a difference there?

  5. janusw commented on Jan 1, 2023

    @janusw
    MemberAuthor

    I've seen users having issues with virtualisation in the past; maybe there's a difference there?

    Hm, not sure what exactly you mean here. I'm not using any kind of virtualization.

  6. janusw commented on Jan 1, 2023

    @janusw
    MemberAuthor

    Btw this issue seems to be somewhat related to oxyplot/oxyplot#497

  7. janusw commented on Jan 1, 2023

    @janusw
    MemberAuthor

    In PR #140, I tried to override the PlotView.Dispose method on Mac (and dispose the Model there, as suggested in oxyplot/oxyplot#497 (comment)), but unfortunately that doesn't seem to help (I still get the same InvalidOperationExceptions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions