我被难住了。
我有几个项目的解决方案。其中有一个小的辅助项目,它只做一些XML读/写。这是一个C#项目,我正在使用System.Xml.Linq名称空间中的XDocument/XElement。该项目的目标是.NET3.5框架。
现在,当我试图运行它时,我得到了一个奇怪的异常:
“$exception{System.Reflection.TargetInvocationException:在Aufrufziel hat einn Ausnahmefehler verursacht中。--->System.IO.FileNotFoundException:Die Datei oder Assembly System.Xml.Linq,Version=3.5.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089 oder eine AbhÃngigkeit davon worde nicht gefunden。这是一个新的系统。”
很抱歉,消息是德语的;我将给出核心部分的翻译:System.IO.FileNotFoundException:File或Assembly System.Xml.Linq,[…]not found。系统找不到文件。
该项目引用位于%programfiles%\Reference Assemblies\Microsoft\Framework\v3.5中的System.Xml.Linq.dll。它存在并在相应的版本和公钥令牌中注册在GAC中。
调试时,异常甚至在跟踪程序进入所述方法之前发生,但在编译代码并运行调用失败方法的项目之后发生。
代码如下:
public static SimpleTree<SankeyItem> XML2Tree(String xml)
{
XDocument document = XDocument.Load(xml);
SimpleTree<SankeyItem> tree = new SimpleTree<SankeyItem>();
XElement element = document.Root;
if (element.Name == "Node")
{
DoSomethingUseful(element)
}
else
{
throw new TreeParseException("Useful message here");
}
return tree;
}
如果我注释掉所有的XSomething代码,它就会工作。拜托,我不知道是什么导致了这个问题。:(
为了完整性起见:字符串“xml”既不是空的也不是空的(“real”代码检查它)。
提前谢谢你!