using System; using System.IO; using System.Reflection; public static class RomLoader { public static byte[] Load(string filename) { // Construct the embedded resource path. // Assuming your project's default namespace is "Desktop" and the folder is "ROMS" string resourceName = $"Desktop.{filename}"; var assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { if (stream == null) { // BULLETPROOFING: If the string is slightly wrong, this will print out // exactly what the compiler actually named your embedded files! string[] availableResources = assembly.GetManifestResourceNames(); string list = string.Join("\n", availableResources); throw new FileNotFoundException($"Could not find embedded ROM: {resourceName}\n\nAvailable embedded files are:\n{list}"); } using (MemoryStream memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); return memoryStream.ToArray(); } } } }