Access Violation when iterating archive variables

Access Violation when iterating archive variables

Im listing the variables in our archive with the function:
C# Code:
private void BindArchiveVariables(TreeNode projNode, IProject iProject) { var variables = iProject.Archives().Item(0).ArchiveVariables(); var cnt = variables.Count; for (int i = 0; i < cnt; i++) { try { var arcvariable = variables.Item(i); if (arcvariable == null) continue; var varname = arcvariable.Name; // <-- Can throw an exception var child = new TreeNode(iProject.String(varname)); projNode.Nodes.Add(child); } catch (Exception ex) { string s = ex.Message; } } }
Two variables (index 940 and 945) in my archive throws an ACCESS_VIOLATION exception at the line: var varname = arcvariable.Name The exception is caught and the VSTA form continues to work, but as soon as I closes the form, but the entire runtime crashes. Is there any way to catch the exception without crashing the runtime, or is it the archive that is corrupt? How should I handle this?

This is a migrated post! Originally posted on 25.04.2012 by user brc. Please be aware that information can be outdated.