While developing a C#-based add-in for Sparx Enterprise Architect, I just encountered a very nasty bug: System.AccessViolationException: Attempted to read or write protected memory. And this is the "evil" code: foreach (EA.Element element in package.Elements). After some googling I found that the translation of "foreach" to a COM operation fails in that specific case. Use the following workaround to get rid of the issue...
