AvaloniaUtils / DialogHost.Avalonia

AvaloniaUI control that provides a simple way to display a dialog with information or prompt the user when information is needed
MIT License
230 stars 15 forks source link

Can't use dialoghost after updating to 0.7.9 #57

Open ekaterinaDS96 opened 4 days ago

ekaterinaDS96 commented 4 days ago

I've just updated Avalonia and DialogHost in my project. And after this update dialoghost doesn't seem to work. I've included DialogHostStyles in App.axaml. But I get exception System.InvalidOperationException: Collection was modified; enumeration operation may not execute Even if I leave the dialoghost empty, I still get this exception. Can anyone please help with this?

SKProCH commented 4 days ago

Hello, @ekaterinaDS96

Can you please provide a stacktrace or a sample project which I can debug?

ekaterinaDS96 commented 4 days ago

@SKProCH Hello! StackTrace:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext()
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Reactive.Disposables.CompositeDisposable.ToList(IEnumerable`1 disposables)
   at System.Reactive.Disposables.CompositeDisposable..ctor(IEnumerable`1 disposables)
   at DialogHostAvalonia.Utilities.MultiDynamicResourceExtension.MultiDynamicResourceObservable..ctor(IEnumerable`1 observables, Object defaultValue)
   at DialogHostAvalonia.Utilities.MultiDynamicResourceExtension.Avalonia.Data.IBinding.Initiate(AvaloniaObject target, AvaloniaProperty targetProperty, Object anchor, Boolean enableDataValidation)
   at Avalonia.Styling.Setter.SetBinding(StyleInstance instance, AvaloniaObject target, IBinding binding)
   at Avalonia.Styling.Setter.Instance(IStyleInstance instance, StyledElement target)
   at Avalonia.Styling.StyleBase.Attach(StyledElement target, IStyleActivator activator, FrameType type, Boolean canShareInstance)
   at Avalonia.Styling.ControlTheme.TryAttach(StyledElement target, FrameType type)
   at Avalonia.StyledElement.ApplyControlTheme(ControlTheme theme, FrameType type)
   at Avalonia.StyledElement.ApplyControlTheme()
   at Avalonia.StyledElement.ApplyStyling()
   at Avalonia.StyledElement.OnAttachedToLogicalTreeCore(LogicalTreeAttachmentEventArgs e)
   at Avalonia.StyledElement.OnAttachedToLogicalTreeCore(LogicalTreeAttachmentEventArgs e)
   at Avalonia.StyledElement.OnAttachedToLogicalTreeCore(LogicalTreeAttachmentEventArgs e)
   at Avalonia.StyledElement.Avalonia.Controls.ISetLogicalParent.SetParent(ILogical parent)
   at Avalonia.StyledElement.SetLogicalParent(IList children)
   at Avalonia.StyledElement.LogicalChildrenCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Visual.LogicalChildrenCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Collections.AvaloniaList`1.NotifyAdd(T item, Int32 index)
   at Avalonia.Collections.AvaloniaList`1.Add(T item)
   at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild(Object content)
   at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild()
   at Avalonia.Controls.Presenters.ContentPresenter.ApplyTemplate()
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutHelper.MeasureChild(Layoutable control, Size availableSize, Thickness padding)
   at Avalonia.Controls.Decorator.MeasureOverride(Size availableSize)
   at Avalonia.Controls.Primitives.VisualLayerManager.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
   at Avalonia.Controls.Window.MeasureOverride(Size availableSize)
   at Avalonia.Controls.WindowBase.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutManager.Measure(Layoutable control)
   at Avalonia.Layout.LayoutManager.ExecuteInitialLayoutPass()
   at Avalonia.Controls.Window.ShowCore(Window owner)
   at Avalonia.Controls.Window.Show()
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.ShowMainWindow()
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at Sphere.Program.Main(String[] args) in C:\Users\...\...\...\...\...\...\Program.cs:line 12

App.axaml:

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:themes="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"
             xmlns:assists="clr-namespace:Material.Styles.Assists;assembly=Material.Styles"
             xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
             xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
           xmlns:sphere="clr-namespace:Sphere"
           xmlns:themes1="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"
           x:Class="Sphere.App">
    <Application.DataTemplates>
        <sphere:ViewLocator/>
    </Application.DataTemplates>
    <Application.Resources>
       <SolidColorBrush Color="#B6A75FF5" Opacity="0.6" x:Key="ColorBrush"/>
       <SolidColorBrush Color="#343232" x:Key="RowBrush"/>
    </Application.Resources>

    <Application.Styles>
      <themes:MaterialTheme PrimaryColor="DeepPurple" SecondaryColor="DeepPurple">
        <themes:MaterialTheme.Resources/>
      </themes:MaterialTheme>
      <dialogHostAvalonia:DialogHostStyles />
      <avalonia:MaterialIconStyles />

    </Application.Styles>
</Application>

I don’t know about a sample project because it really crashes even if a UserControl looks like

image

SKProCH commented 1 day ago

I can't actually reproduce it, by creating a project and pasting your code. Can you create and share a sample project (via zip or github repository) which I can launch and get the exception.

P.S. Also

<themes:MaterialTheme PrimaryColor="DeepPurple" SecondaryColor="DeepPurple">
  <themes:MaterialTheme.Resources/>
</themes:MaterialTheme>

isn't supposed to be like this.
It's better to not include a MaterialTheme.Resources inside of MaterialTheme. Just use the

<themes:MaterialTheme PrimaryColor="DeepPurple" SecondaryColor="DeepPurple"></themes:MaterialTheme>

Anyway, i can't debug this problem without a sample project where is error can be reproduced.