Bug? Error loading file. Given key was not present in the dictionary.

Computersmith64

Well-Known Member
Licensed User
Longtime User
Had this issue today after several weeks of working on a new project. The exact events leading up to it are a little hazy however it was something like:

Using v7.30 BETA #1

* Was going through the .bal files in turn to check that I had AutoScaleRate set.

* Even .bal files that weren't being changed were asking to be saved (I assume because it was the first time I'd opened them with this version of B4A).

* Realized there was one .bal (& associated activity) file I no longer need in this project, so went back to the IDE, clicked on the associated activity tab, then "Project -> Remove Module". After this, the tab was still there, then about 10 seconds later the "Error Loading File" error came up.

* Closed B4A, then reopened by selecting the project from the jump list & immediately got the "Error Loading File" error & was left with a project with only 3 modules in it (Main, Starter & 1 other) - where there were previously 19 modules.

* Had a panic attack thinking that best case was I would lose all the work I had done today (about 10 hours) & worst case the whole project (I hadn't checked to see if my backups are working properly) - however when I looked in Windows Explorer I discovered that all the files were still in the project directories, so calmed down a bit. :)

* Hunted through the forum & found numerous reports of this issue dating back to 2011, some suggestions on possible causes, but no definitive fix.

* Saw posts from Erel saying to check the B4A file for corruption but couldn't see anything obvious in there.

* Saw a post suggesting to delete the meta file so did this & the project loaded correctly. I did get an error but that was because I had removed the .bal manually & it was still listed in the files tab, so loading it failed. I was able to remove that file from the files tab & everything was good.

There is definitely some kind of bug there, seemingly related to the Designer. What's really scary is that I suspect if I'd tried to run the corrupted project, my original project would have been overwritten (by autosave) & I'd have lost the lot. Fortunately I do have a daily backup, but I still would have lost about 10 hours of work I did today.

Given the number of times this issue has been reported over the past 5+ years & the potentially disastrous nature of it, I'm surprised it hasn't been fixed.

- Colin.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Given the number of times this issue has been reported over the past 5+ years & the potentially disastrous nature of it, I'm surprised it hasn't been fixed.
There were many improvements related to the way the IDE handles files. The IDE never writes to the project files except when the project is saved. During saving the data is actually written only if all steps were successful.
There are no known bugs related to the "hard" corruption of project files (where the file becomes empty or all NULL values). A system crash while the project is saved can cause this.

You can always open the project file with a text editor and check its content.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
You can always open the project file with a text editor and check its content.

Yeah - it's great that the project file is in a format that's human readable, but I had no idea what to look for - & as it turned out, the issue seems to have been in the meta file (although I looked in there & didn't see anything obviously wrong - again, not that I knew what to look for).

I'm wondering if more descriptive error messages would help. Like "Error loading [file name]. The [key] key was not present in the dictionary in [file]." Perhaps also a quick tutorial on the possible causes of this error & suggestions on what to look for in the project & meta files in order to resolve it.

- Colin.
 
Top