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); typeDefinition.Fields.Add(fieldDef);
Any help would be greatly appreciated.