This is a migrated thread and some comments may be shown as answers.

InvalidOperationException

1 Answer 101 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 19 Oct 2015, 03:22 PM

Hi,

When I added Telerik to my application, I used .Net framework 4.5 and platform target x86. I used a RadCarousel and it worked perfect. Later I had to switch to .Net 4.0 framework and change the Telerik version to v.2014.3.1021.40. But now I have a problem. I reduced the code to a minimum for a test purposes:

<Window x:Class="myBRH.AddPhotosWnd"
         
        Title="AddPhotosWnd" Height="300" Width="1024">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10*"/>
            <ColumnDefinition Width="135*"/>
            <ColumnDefinition Width="855*"/>
            <ColumnDefinition Width="16*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="10*"/>
            <RowDefinition Height="3*"/>
            <RowDefinition Height="36*"/>
            <RowDefinition Height="3*"/>
        </Grid.RowDefinitions>
        <Button
            Grid.Column="1" Grid.Row="1" Click="Button_Click"/>
 
        <telerik:RadCarousel x:Name="rc" Grid.Column="1" Grid.ColumnSpan="2"
                             Grid.Row="3" HorizontalScrollBarVisibility="Hidden"/>
    </Grid>
</Window>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
 
namespace myBRH
{
    /// <summary>
    /// Interaction logic for AddPhotosWnd.xaml
    /// </summary>
    public partial class AddPhotosWnd : Window
    {
        public AddPhotosWnd()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string str = "sdfsd";
            rc.Items.Add(str);
            rc.BringDataItemIntoView(rc.Items[0]);
        }
    }
}
 

 The problem:

When second item is added to the RadCarousel.Items,  System.InvalidOperationException is thrown  with the message: "Collection was modified; enumeration operation may not execute."

Exception is not thrown if I comment out the rc.BringDataItemIntoView(rc.Items[0]); method call.

 

 

 

 

 

<Window x:Class="mytest.Wnd"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       
        Height="300" Width="1024">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10*"/>
            <ColumnDefinition Width="135*"/>
            <ColumnDefinition Width="855*"/>
            <ColumnDefinition Width="16*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="10*"/>
            <RowDefinition Height="3*"/>
            <RowDefinition Height="36*"/>
            <RowDefinition Height="3*"/>
        </Grid.RowDefinitions>
        <Button
            Grid.Column="1" Grid.Row="1" Click="Button_Click"/>
 
        <telerik:RadCarousel x:Name="rc" Grid.Column="1" Grid.ColumnSpan="2"
                             Grid.Row="3" HorizontalScrollBarVisibility="Hidden"/>
    </Grid>
</Window>

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Oct 2015, 08:16 AM
Hello Mark,

I tried to reproduce the exception but without any success. Could you take a look at the project attached and let me know whether there is anything missing ? What should be updated in order to get the same behavior as the one on your side ?

Regards,
Maya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Carousel
Asked by
Mark
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or