Can’t Find Resource node.exe

I have a program that is currently taking a specific Javascript file and it’s going to prettify it for me. The method provided by ChatGPT 4.0 is supposed to work but I am having a hard time having my code see that I do have node.exe embedded as a file. It’s there, and I have the .exe in multiple locations within the project folders for verification. What Am I doing wrong? Here is the code:


using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using Flurl.Http;

namespace JSFilePrettifier
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        public static async Task DownloadFileAsync(string fileUrl, string fileName, Action<string> updateStatus)
        {
            try
            {
                var tempFilePath = Path.GetTempFileName();
                await fileUrl.DownloadFileAsync(Path.GetDirectoryName(tempFilePath), Path.GetFileName(tempFilePath));

                var totalBytes = new FileInfo(tempFilePath).Length;
                updateStatus($"Total file size: {totalBytes} bytes");

                using (var inputStream = new FileStream(tempFilePath, FileMode.Open, FileAccess.Read))
                using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var buffer = new byte[8192];
                    long totalRead = 0L;
                    int bytesRead;
                    while ((bytesRead = await inputStream.ReadAsync(buffer, 0, buffer.Length)) != 0)
                    {
                        await fileStream.WriteAsync(buffer, 0, bytesRead);
                        totalRead += bytesRead;

                        if (totalBytes != -1L)
                        {
                            double progress = (double)totalRead / totalBytes * 100;
                            updateStatus($"Downloaded {totalRead} of {totalBytes} bytes ({progress:0.00}%)");
                        }
                        else
                        {
                            updateStatus($"Downloaded {totalRead} bytes");
                        }
                    }

                    updateStatus($"Final downloaded size: {totalRead} bytes");
                }

                File.Delete(tempFilePath);
                updateStatus("Download complete.");
            }
            catch (Exception ex)
            {
                updateStatus($"Error: {ex.Message}");
            }
        }

        public static string PrettifyJavaScript(string jsCode)
        {
            try
            {
                string nodePath = ExtractResource("node");
                string jsBeautifierPath = ExtractResource("JSFilePrettifier.Resources.js_beautify");
                string tempInputPath = Path.GetTempFileName();
                string tempOutputPath = Path.GetTempFileName();

                File.WriteAllText(tempInputPath, jsCode);

                var startInfo = new ProcessStartInfo
                {
                    FileName = nodePath,
                    Arguments = $"{jsBeautifierPath} {tempInputPath} -o {tempOutputPath}",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                };

                using (var process = Process.Start(startInfo))
                {
                    process.WaitForExit();
                }

                string prettifiedJsCode = File.ReadAllText(tempOutputPath);

                File.Delete(tempInputPath);
                File.Delete(tempOutputPath);

                return prettifiedJsCode;
            }
            catch (Exception ex)
            {
                throw new Exception($"Error during prettification: {ex.Message}");
            }
        }

        public static string ExtractResource(string resourceName)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var resourcePath = $"{resourceName}";

            using (var stream = assembly.GetManifestResourceStream(resourcePath))
            {
                if (stream == null)
                    throw new Exception($"Resource '{resourcePath}' not found.");

                var tempPath = Path.GetTempFileName();
                using (var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write))
                {
                    stream.CopyTo(fileStream);
                }

                return tempPath;
            }
        }

        public static string GetOutputFilePath(string inputFilePath)
        {
            string directory = Path.GetDirectoryName(inputFilePath);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(inputFilePath);
            string outputFileName = fileNameWithoutExtension + "-Decompiled.js";
            return Path.Combine(directory, outputFileName);
        }
    }
}

I am getting an error at this line:

catch (Exception ex)
{
    throw new Exception($"Error during prettification: {ex.Message}");
}

And this is the Error I am receiving:

  • System.Exception: ‘Error during prettification: Resource ‘node’ not found.’

Here are the photos showing what I have in the Resources:

Showing the Resources

Node.exe is set as an embedded Resource

Can someone look at my code and see what is wrong and why I am getting this error?

I tried revising the code multiple time, including the name of the resource as well as the name of the file that it’s looking for in the code.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật