Altering "Assembly-CSharp.dll" with Mono Cecil produces a zero bytes dll

We want to bring a few of Cecil’s post-processing features into our Unity game, but have run into an unknown issue I haven’t seen anyone get. Basically, in our post-processor file (Assets/Editor/SixMinutePostprocess.cs),

using UnityEditor;
using System;
using Mono.Cecil;

[InitializeOnLoadAttribute]
static class SixMinutePostprocess
{
	static SixMinutePostprocess()
	{
		Console.WriteLine("Init AssemblyPostProcessor");
		string path = "Library/ScriptAssemblies/Assembly-CSharp.dll";
		
		ModuleDefinition.ReadModule(path).Write(path);
	}
}

But when that’s done, Unity’s main application gives out about all sorts of things missing, and when you check the newly altered dll, it’s an empty file, zero bytes. Running similar code outside of Unity gives expected results, but I can’t figure out how to get it to run properly with Unity’s builders.

I’m using the Cecil build from Unity’s own Github, Releases · Unity-Technologies/cecil · GitHub (which, as I said, works as expected in another project).

You need to add module search paths to your ReadModule call.

		// this will add paths for all your currently loaded assemblies
		DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();
		foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) 
			resolver.AddSearchDirectory(Path.GetDirectoryName(assembly.Location));
		ReaderParameters parameters = new ReaderParameters { AssemblyResolver = resolver };

		AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(path, parameters);