MaterialProcessor fails on DualTextureMaterialContent

I am getting the error below when my custom dual texture model has it’s material
processed. Googling the source below the error for MaterialProcessor.cs it seems
that the code will always fail for more then 1 texture because the enumeration can not be modified while being enumerated.

C:/Dev/GameKit/Game/Content/Dungeons/Dungeon1.model: error: Processor ‘ModelProcessor’ had unexpected failure!
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Enumerator.MoveNext() at Microsoft.Xna.Framework.Content.Pipeline.Processors.MaterialProcessor.Process(MaterialContent input, ContentProcessorContext context) at Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context)
at MonoGame.Framework.Content.Pipeline.Builder.PipelineProcessorContext.Convert[TInput,TOutput](TInput input, String processorName, OpaqueDataDictionary processorParameters)
at Microsoft.Xna.Framework.Content.Pipeline.Processors.ModelProcessor.Process(NodeContent input, ContentProcessorContext context)
at Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor`2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context)
at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent)
Build 1 succeeded, 1 failed.

     /// <summary> 

139 /// Builds the texture and effect content for the material.
140 ///
141 /// The material content to build.
142 /// Context for the specified processor.
143 /// The built material.
144 /// If the MaterialContent is of type EffectMaterialContent, a build is requested for Effect, and validation will be performed on the OpaqueData to ensure that all parameters are valid input to SetValue or SetValueTranspose. If the MaterialContent is a BasicMaterialContent, no validation will be performed on OpaqueData. Process requests builds for all textures in Textures, unless the MaterialContent is of type BasicMaterialContent, in which case a build will only be requested for DiffuseColor. The textures in Textures will be ignored.
145 public override MaterialContent Process(MaterialContent input, ContentProcessorContext context)
146 {
147 // Docs say that if it’s a basic effect, only build the diffuse texture.
148 var basic = input as BasicMaterialContent;
149 if (basic != null)
150 {
151 ExternalReference texture;
152 if (basic.Textures.TryGetValue(BasicMaterialContent.TextureKey, out texture))
153 basic.Texture = BuildTexture(texture.Filename, texture, context);

155 return basic;
156 }

158 // Build custom effects
159 var effectMaterial = input as EffectMaterialContent;
160 if (effectMaterial != null)
161 {
162 effectMaterial.CompiledEffect = BuildEffect(effectMaterial.Effect, context);
163 // TODO: Docs say to validate OpaqueData for SetValue/SetValueTranspose
164 // Does that mean to match up with effect param names??
165 }

167 // Build all textures
168 foreach (var texture in input.Textures)
169 {
170 var builtTexture = BuildTexture(texture.Value.Filename, texture.Value, context);
171 input.Textures[texture.Key] = builtTexture;
172 }

174 return input;
175 }

Did you try with a standard for loop instead of a foreach one ?

This is not in my code it is in MaterialProcessor.cs (built into mono game) it seems that code is wrong when processing DualTextureMaterialContent. It works for BasicMaterialContent though since that is only 1 texture.