Provide a way to generate a new assembly after a predetermined number of types as been generated


  • Generating multiple assemblies inside a code generator must become a first class citizen given that there are still bugs in .NET 4.5 that will cause the creation of new types to slow down significantly with the number of types created in an assembly. Only about 100 types (with 150 types being the reasonable maximum) can be efficiently created for each assembly.

  • IGeneratedCodeFlusher.FlushAssembliesToDisk should return a string array instead of a scalar value.

  • A new ModuleContext needs to be created after a pre-determined number of types has been reached.

  • The logic should (must?) support switching to a new assembly also for additional types but not when the additional type is generated in the context of an assembled type.

  • The new implementation also has to deal with the DebugInfoGenerator. Possibly, each assembly needs its own instance.

  • Evaluate if maybe we can use multiple modules for each assembly and still avoid the performance penalty. This could make the CodeGenerator API simpler.


Michael Ketting
June 28, 2016, 3:38 PM

Notes (to be translated worked into the description):
TypeCache erzeugt einen neuen AssemblyContext wenn am Ende der Type Generierung die bestehende Assembly „voll“ ist. Der alte AssemblyContext muss separat aufgehoben werden, der neue wird enqued. U.U. auch eher direkt im AssemblyContextPool einbauen (vermutlich direkt im AssemblyContextPool, nicht decorator). Zusätzlich zu DequeueAll noch ein DrainFullAssemblyContext() API.

Oder, bessere Lösung: beim Dequeue wird am AssemblyContext (oder decorator) im AssemblyContextPool gerpüft, ob dieser voll ist. Wenn ja, wird er zuerst „resetted“. Damit muss kein neuer AssemblyContext erzeugt werden.

GeneratedTypeCount muss am AssembylContext bzw dem ReflectionEmitCodeGenerator exposed warden. Oder, alternativ, es gibt auf dem ReflectionEmitCodeGenerator eine Ensure method genau dafür.




Michael Ketting



Time tracking


Time remaining



Fix versions