TL;DR: System restart (for ex. due to Windows update) can irreversibly corrupt .sch (legacy KiCad 5 schematic files) which were open in an existing session of v6 or v7 schema editor, and not previously converted to the new schematic format (saved).
Complete story:
This post is a general warning to the community with some hope of finding a solution, but also to highlight a serious existing bug in V6/7 that can corrupt your projects!
I’ve had a lot of schematic files created in Ver.5 which I now cannot open neither in v5, v6 or v7. Upon opening those .sch files I’d get the following error:
“Error loading schematic ‘file directory’
invalid symbol library definition in ‘directory’ line 1926, offset 2”
I’ve come to a conclusion that those schematic files were irreversibly corrupted by opening them in KiCad 6 and 7 and not saving them properly, and I think I’ve figured out how and when that happens!
Below is one of the scenarios that can create a corrupted .sch file (and lost project if there are no back-ups available):
When working on a new project in KiCad 6 or 7, I’d sometimes open older schematic files created in v5 to see how I did certain elements in the schema. Naturally when opening older files in v6/7, the schematic editor will show a warning message that the file was created by an older version and upon saving it will be converted to a new format (they fail to mention that there will be a new file created and original will remain untouched!). Thinking that the older version file/project is final and I don’t want to mess with it, I decided that I don’t want to “save” and convert it to a new format, as I just need to see it as a reference. Sometimes I’d work late into the night and leave everything open, thinking I’d continue the next day. When getting back to working on the project the next day, everything seems to be the same as I’ve left it. I’d finish up the new project, close out the files, shut down the pc and go on with my life.
The next time when I try to open the old .sch schematic file I see that the file was last modified the same day when I closed out of it without saving - weird, it should not have been modified, but it was; and the next thing I see is a nasty surprise error message after which Schema editor crushes.
I’ve had at least 4 projects ruined this way, and now I think I’ve figured out how this happens!!! Apparently if you leave old .sch files open overnight without previously converting them to a new format and the Windows all of the sudden decides it needs a reboot due to an update, the newer schema editor still writes something into the file (or maybe windows itself), altering and damaging the file in the process, which renders it corrupt the next time you try opening it! This is really hard to detect since you typically would not know if your system has rebooted overnight without your will, unless you go through the logs every day.
Current remedy for this is to immediately convert older schema files to a new version without worrying that something will get altered since KiCad will be creating a new file anyways. I wish this was more clear upfront so that it would not deter me from converting those earlier!
I’ve seen a few other posts referencing to the same error/issue, so it might be helpful to the community at least to avoid such cases, but I’d appreciate if anyone has figured out a way to fix those files!