Bug 26456 - Add implicit style cause enumeration exception
Summary: Add implicit style cause enumeration exception
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.2
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-27 07:45 UTC by Thomas Hagström
Modified: 2016-04-08 19:16 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Thomas Hagström 2015-01-27 07:45:08 UTC
I followed the documentation to add implicit styles from code to my App.cs in PCL project.

if (Current.Resources == null)
        {
            Current.Resources = new ResourceDictionary();
        }

        Current.Resources.Add(
            new Style(typeof(Label))
                {
                    BaseResourceKey = Device.Styles.BodyStyleKey,
                    Setters =
                        {
                            new Setter
                                {
                                    Property = Label.TextColorProperty,
                                    Value = Color.White
                                }
                        }
                });

Trying to run this on either Windows Phone or Android gives the exception

"System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at [...] Xamarin.Forms.Element.OnResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Xamarin.Forms.MergedResourceDictionary..."

Question on Stack Overflow:
http://stackoverflow.com/questions/28141545/collection-modified-error-when-adding-implicit-style-from-code-to-xamarin-forms
Comment 1 Udham Singh 2015-01-29 08:25:10 UTC
I have checked this issue with the help of code given in bug with Xamarin.Forms 1.3.1.6296 and able to reproduce this issue at my end.

Screencast with Xamarin.Forms 1.3.1.6296 : http://www.screencast.com/t/VQZuiZyPevtw

I have also checked this issue with Xamarin.Forms.1.3.2.6309-pre2 and this is working fine. 

Screencast with Xamarin.Forms 1.3.2.6309-pre2 : http://www.screencast.com/t/eAjfy0DG

Could you please check this with Xamarin.Forms 1.3.2.6309-pre2 and let us know if you are still getting this issue along with Zip Xamarin Logs, Application output and exception log.

Thanks!

Environment Info :

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.50938

Xamarin   3.9.291.0 (9f3e552)
Comment 2 Rui Marinho 2016-04-08 19:16:21 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d