Attempting to access or read a file at a path that does not exist on disk.
This exception is thrown when an attempt to access a file that does not exist on disk fails.
Providing an incorrect file path, neglecting relative directory offsets, or attempting to open files deleted by another process.
1using System;2using System.IO;3 4public class Program {5 public static void Main() {6 // Bug: Config file path does not exist7 string content = File.ReadAllText("config.json"); 8 }9}1using System;2using System.IO;3 4public class Program {5 public static void Main() {6 string path = "config.json";7 8 // Fix: Check File.Exists before reading9 if (File.Exists(path)) {10 string content = File.ReadAllText(path);11 Console.WriteLine("Config loaded successfully.");12 } else {13 Console.WriteLine($"Config file not found at: {Path.GetFullPath(path)}");14 }15 }16}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
The File.ReadAllText method attempts to locate 'config.json' in the current working directory. Since the file is missing, the runtime throws System.IO.FileNotFoundException.