【发布时间】:2012-10-17 14:32:57
【问题描述】:
我正在尝试从程序集中读取 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);
空引用异常未处理,它说空。有什么帮助???
【问题讨论】:
-
如何获取传递给
Form1的程序集引用? -
你检查你
testAssembly是否为空?? -
我已经更新了我的问题,testAssembly 不为空,我可以看到 xml 文件名。我的 xml 文件在同一个项目中并且是嵌入的。
-
@linguini - 根据您发布的屏幕截图中的
NullReferenceException,我认为 testAssembly 是null。 -
在完全相同的情况下显示屏幕,但将鼠标悬停在
testAssembly
标签: c# xml winforms .net-assembly