Detection of collection modifications during its enumeration in the C# source code using static analysis


Detection of collection modifications during its enumeration in the C# source code using static analysis

Khanevskaya K.A. (ISP RAS, Moscow, Russia; MIPT, Dolgoprudny, Moscow Region, Russia)
Tsiazhkorob U.V. (ISP RAS, Moscow, Russia; MIPT, Dolgoprudny, Moscow Region, Russia)
Ignatiev V.N. (ISP RAS, Moscow, Russia; MSU, Moscow, Russia)

Abstract

The article is dedicated to the development of the method for detecting collection modification error during their enumeration in C# programs. Such errors lead to an InvalidOperationException and program crash at runtime. The proposed solution is implemented within the industrial static analyzer SharpChecker and uses interprocedural symbolic analysis, sensitive to control flow and execution paths. The detector tracks both direct modifications of collections within a foreach loop and modifications occurring through chains of method calls. Testing on open-source projects showed an accuracy of about 69%. The results demonstrate the effectiveness of the approach for detecting complex cases of collection modification.

Keywords

static analysis; symbolic execution; bug detection; collection modification; collection enumeration.

Edition

Proceedings of the Institute for System Programming, vol. 38, issue 3, part 1, 2026, pp. 129-142

ISSN 2220-6426 (Online), ISSN 2079-8156 (Print).

DOI: 10.15514/ISPRAS-2026-38(3)-7

For citation

Khanevskaya K.A., Tsiazhkorob U.V., Ignatiev V.N. Detection of collection modifications during its enumeration in the C# source code using static analysis. Proceedings of the Institute for System Programming, vol. 38, issue 3, part 1, 2026, pp. 129-142 DOI: 10.15514/ISPRAS-2026-38(3)-7.

Full text of the paper in pdf (in Russian) Back to the contents of the volume