KiCad 6/7 irreversibly corrupts schematic files created in KiCad 5 (after Windows reboot due to update)

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!

And this is why you copy the files from V5 to newer version directory structure and open them with V6/V7.
Windows supports having V5, V6 and V7 installed on the same machine in parallel.

V6 creates new versions of V5 files with new extensions. So V5 versions may still be there.
Can you read them with a text editor?
Newer KiCad also makes periodic backups.

OS updates can do absolutely anything to any running applications and open files, totally beyond KiCads control.

Copy old files to a new directory tree is just a variation on taking a backup, good hygiene on any major software upgrade

While I think the reply posted above is a bit harsh, I strongly suggest keeping regular backups and using one of the many version control systems (subversion, git, or similar). Depending on having only one copy is always a serious risk.

That said, I don’t believe KiCad should have overwritten your files. Even when opening an old version file, nothing should be overwritten until and unless the user explicitly clicks on “Save”.

1 Like

Yes you would, you would be logged off/out and all your applications closed including KiCAD which you have said was left open.

Maybe it’s Autosave ?


Can you provide a broken .sch file? Would be interesting to see the content.
Even more intressting would be to see a working file and the corrupt version of the same file.

Do you have the file history enabled? Maybe the older files are still there?

Is it possible that KiCad gets closed during writing? Maybe autosave + reboot or something like OOM-Killer killing KiCad?

I agree that having back-ups and so on is a good hygiene, but it is merely a remedy to a bug, not a solution. The issue is still there and it will corrupt files, maybe not mine anymore (as I’ve learned my lesson), but someone else will face the same problem. I’ve posted this with a sole purpose to warn others, did not expect to make someone ****hurt (but there are always some people who think they are the smartest and I take no offense).

I totally agree that KiCad should not make any changes to files unless explicitly given permissions to do so via user input (“save”/autosave), yet it somehow does! There is no such issue in V5 app working on V5 files or V6/7 app working on the new format, only having V5 files open with V6/7 app and having that windows update or whatever else that may trigger system restart.

Not always you get logged off, sometimes system reboots and opens all the same windows you’ve been working on as it saves your session and restores it after reboot. Only the major updates will log you off during restart but then you generally get a notice that system restart is needed.

But I agree with you, it may be something related to how autosave function behaves in those conditions and instead of saving the files it inadvertently corrupts them.

Unfortunately since I’m a new user I cannot upload any files and did not use any git for version tracking. I can still open the files in text editor and even comment out the part lines that supposedly cause the issue but then KiCad would show me the next part (set o lines) as causing the same error.

I am pretty sure this is due to something related to saving for reboot operations.

The second line of this text is what schema editor is not liking in the corrupted file. There was a space after "Male " which I’ve tried deleting as well but did not fix it.

L Connector:Conn_01x01_Male
U 1 1 60F53195
P 14450 7450
AR Path=“/60F53195” Ref=“” Part=“1”
AR Path=“/60F53195” Ref=“J13” Part=“1”
F 0 “J13” H 14400 7550 50 0000 C CNN
F 1 “Touch btn” H 14500 7400 50 0000 C CNN
F 2 “AAV_Footprint Library:Sensor_BTN” H 14450 7450 50 0001 C CNN
F 3 “~” H 14450 7450 50 0001 C CNN
1 14450 7450
1 0 0 -1

Fixed. Welcome aboard.

Help us help you.

Please zip up your project (to capture any back up files and the older version files) and share it.

I also migrated from KiCad 5 to 6 but noticed the old KiCad 5 files are in my repository so I can still open them with KiCad 5.

IIRC there was some scary migration of either or both schematic symbols and PCB footprints which if I understood what I was doing would not have been hard but or course I did not because it was all new.