Blog Archives

Collection Was Modified; Enumeraton Operation May Not Execute

Some Background

This was a very interesting bug for me to track down.  Initially it did not bubble up as the error that is in this title.  Initially it revealed itself as an out of bounds error when I tried to set IsOpen to true for a ContextMenu in a Silverlight project.  After lots of debugging I finally landed on this culprit.

The Task

The task I was trying to accomplish was pretty straight forward.  Given a List<T> remove any duplicate entries based on a given object.  Again, a straight forward task, or so I thought.

foreach(MyClass item in myListOfMyClass)
    if(item.SomeValue == objectOfMyClass.SomeValue)

Read the rest of this entry

Breaking Into Your Lambda

I just learned something new today at Microsoft Virtual Academy.  Heck I almost always learn something new or even things I forgot at Microsoft Virtual Academy.  In this case I thought it was pretty neat.  We all use break points throughout our code, most of the time I just break on a line.  I just learned how to break into a Lambda expression.

Basically you click inside your Lambda expression and then press F9.  To show this I will create a quick class called Stuff.

    public class Stuff
        public string Name { get; set; }
        public int Quantity { get; set; }

In another area I am going to use this class to create a List<Stuff> and then use a Lambda on that list.

            List someStuff = new List()
                                new Stuff{Name = "Dice", Quantity = 2}, 
                                new Stuff{Name="Cards", Quantity = 52}, 
                                new Stuff{Name = "Tokens", Quantity = 20}

            var result = someStuff.Where(s => s.Name.Length > 4);

Next I click in my Lambda and press F9, below is a screenshot of the break point inside my Lambda.

Breaking Into Lambda

Debugging A Silverlight Project With Windows 7 & VS2012

This is something I tend to forget from time to time.  When I look on the Internet I do find some help but the names do not line up exactly the same for me.  For this post I am using Windows 7 and Visual Studio 2012.

With Silverlight, if you start it in debug mode you may end up debugging the client or the server.  I find it much easier to do the following.

  1. Start Internet Explorer, I suppose you could use any browser of choice but for Silverlight debugging I prefer to stay in IE.
    1. Browse to your Silverlight application using http://localhost&#8230;.  I get that url by running it in Visual Studio and just adding it to my favorites.
  2. In Visual Studio click on the Debug menu item at the top, then click on Attach to Process.
  3. There are three processes I attach it to:
    1. iexplore.exe
      1. Two of these, one is listed with the title of the Silverlight home page the other has a type of Silverlight
    2. w3wp.exe
      1. For my environment this has a Type of Managed and a User Name of IIS APPOOL\DefaultAppPool
  4. You may receive an Attach warning (see image below).  You selected this and know what it is so click Attach.


For me that’s it, I’m now debugging a large Silverlight 4 application and hitting my various break points.  I hope this helps some people other than just me.