Threading is somehow included in my Flash Build, how to I track down what's using it?

I’m making a flash build of a tiny game. When I started porting it, there were a ton of issues being thrown by the build step FlashDotNetAPIValidationRule (things like System.TextBuilder.AppendLine is not supported). These were easy enough to port, but now I’m down to my last error:

 Usage of a type or method not supported by Unity Flash.
* Details:   Invokes an unsupported method System.Int32 System.Threading.Interlocked::CompareExchange(System.Int32&,System.Int32,System.Int32) on type System.Threading.Interlocked
* Source:   debugging symbols unavailable, IL offset 0x0009 at line : 0

I’ve searched around my project for anything obvious that would be using threads and then I just started commenting out systems that could even conceivably touch threads, but I haven’t figured out what’s using threads. Does anyone have any advice for tracing code dependencies so that I can debug this sort of problem?

If all your assemblies are compiled by Unity, then setting “development build” checkbox in the build menu will allow you to track these down.

This issue is caused with yields in for loops:

public IEnumerable<Moo> Moos
{
   get
   {
      foreach (Moo moo in moos)
          yield return moo;  // ERROR
   }
}

To solve it, do not return the enumerated object.

public IEnumerable<Moo> Moos
{
   get
   {
#if UNITY_FLASH
      List<Moo> res = new List<Moo>(); 
      foreach (Moo moo in moos)
          res.Add(moo); 
      return res;  // somewhat defeats the purpose, but wth
#else
      foreach (Moo moo in moos)
          yield return moo;  // ERROR
#endif

   }
}

Enjoy,
frevd