- Home /
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);
typeDefinition.Fields.Add(fieldDef);
Any help would be greatly appreciated.
Answer by Catchawink · Mar 22, 2021 at 11:50 PM
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.
Hi, I got similar problem too.
Scripts won't change after first play but when I restart editor it works fine.
How did you resolve exactly??
Your answer
Follow this Question
Related Questions
ApplicationException: Unable to find a suitable compiler? 1 Answer
Assembly Definition Files exclude specified subfolder 0 Answers
Compile Error (CS0246) appears for every script in the project. 0 Answers
enable multidex for android build 2 Answers
Can/should mcs.rsp files be used to reference my own class libraries? 0 Answers