Fix null ref when writing assembly to runtime