Script won't update after first successful weaving with Mono.Cecil

I’m using Mono.Cecil to modify assemblies post compilation (I’m using this implementation of Mono.Cecil within Unity). For some reason, if I add a field to a type in an assembly, and the type of the field is a delegate type that I’ve defined, scripts in the assembly don’t appear to update after the first successful modification/weaving.

The following code runs correctly every time I recompile, but if I attempt to replace PropertyChangedEventHandler with a custom delegate type, the assembly compiles and weaves correctly only once, then refuses to compile/update with newer script changes. It only works again if I restart Unity. I’m not receiving any error messages:

var handlerReference = typeDefinition.Module.ImportReference(typeof(System.ComponentModel.PropertyChangedEventHandler));

var fieldDef = new FieldDefinition(nameof(INotifyMethodCalled.MethodCalled), FieldAttributes.Private | FieldAttributes.NotSerialized, handlerReference);


Any help would be greatly appreciated.

I just resolved my issue–the script doing the weaving was referencing the assembly it was weaving. This was the programmatic equivalent of a snake eating its tail and choking on it. The script using Mono.Cecil no longer references its target assembly.