The idea here is to extract a batch file from an embedded resource to a temporary directory on the C drive, then run that extracted batch file. The issue I'm running into is an error of "Object reference not set to an instance of an object."
The code is:
public static void ExtractResource()
{
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(Namespace.Properties.Resources.Backup))
{
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, buffer.Length);
using (var sw = new BinaryWriter(File.Open(@"C:\test.bat", FileMode.OpenOrCreate)))
{
sw.Write(buffer);
}
}
}
The error occurs on this line:
byte[] buffer = new byte[s.Length];