我正在尝试从程序集中读取 xml 文件,这是我的代码:
private Assembly testAssembly;
private void button1_Click(object sender, EventArgs e)
{
string testfile = "stack.xml";
String testfileName = string.Format("{0}.{1}", testAssembly.GetName().Name, testfile);
using (Stream stream = testAssembly.GetManifestResourceStream(testfileName))
{
using (StreamReader sr = new StreamReader(stream))
{
var value = sr.ReadToEnd();
Console.WriteLine("The read file is {0}", value);
}
}
}
我在这条线上有一个问题:
String testfileName = string.Format("{0}.{1}", testAssembly.GetName().Name,
testfile);
未处理的空引用异常,它说空。有什么帮助???