Blazored / Modal

A powerful and customizable modal implementation for Blazor applications.
https://blazored.github.io/Modal/
MIT License
786 stars 186 forks source link

[Bug] 5.0.3 Throws InvalidaOperationException #230

Closed dfkeenan closed 4 years ago

dfkeenan commented 4 years ago

Describe the bug After updating from 5.0.2 to 5.0.3 I started getting System.InvalidOperationException: Collection was modified; enumeration operation may not execute. Happens in the Blazored.Modal.BlazoredModal.CancelModals method.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior Not throw exception

Screenshots If applicable, add screenshots to help explain your problem.

Hosting Model (is this issue happening with a certain hosting model?): I am currently using

Additional context I am using the CEC.Routing package to prevent users from navigating with unsaved changes. The modal is being shown upon navigation.

Enfis commented 4 years ago

Same here,

Here a await Task.Yield (); just after the Modal await, probably await dialog.Result, (temporary) solves the problem.

larsk2009 commented 4 years ago

Could you provide some clear steps to reproduce this issue, or a repo showing this problem?

Enfis commented 4 years ago

This is the simplest project using default Blazor wasm template, hope this help, just press "TEst Modal" button.

TestModal.zip

larsk2009 commented 4 years ago

Ah Right, I may be getting what is going wrong. I will try some stuff to see if I can fix it.

EDIT: Forgot to mention what I think is the problem: The NavigationManager is navigating away from the page, which causes all modals on screen to be closed. Only problem is, the modal is already being closed by BlazoredModal.Close. Thus, while closing all modals, the collection of modals changes which causes this problem.

larsk2009 commented 4 years ago

I can reproduce it in the sample project as well. I might have a fix for it, so I will make a PR so we can all review it.