嵌入的资源在这里的想法是从嵌入式资源的批处理文件解压到C盘上的临时目录,然后提取该批处理文件运行。我遇到的问题是“对象引用未设置为对象实例”的错误。有问题提取C#应用程序
的代码是:
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);
}
}
}
在此行中出现的错误:
byte[] buffer = new byte[s.Length];
根据[doco](http://msdn.microsoft.com/en-us/library/5kx66y1a.aspx)。清单资源;如果在编译期间没有指定资源,或者资源对调用者不可见,则为null。 –
@darkstarohio对这些建议的反馈是什么? –