这是我的场景:
我有三个项目:两个 DLL 和一个控制台应用程序,让我们将它们命名为 foo.dll、bar.dll 和 console.exe。Console.exe 使用 Assembly.LoadFile(@"c:\foo.dll") 加载 foo.dll。Foo.dll 的项目引用了 bar.dll 并使用了一个类。Console.exe 加载 foo.dll 很好,当 foo.dll 尝试使用 bar.dll 的类时会出现问题。我收到“无法加载程序集:“bar.dll”等等等等异常。
几点:
所以一切都在同一个本地目录中,正确的 dll 被引用(通过项目属性,我已经使用 Reflector 来确保程序集版本正确)。如果我将 bar.dll 安装到 GAC,一切都会按预期进行。
我认为这与 Assembly.LoadFile 调用有关,并跳转到第二个 DLL,但我不确定。
感谢您的时间和投入。
我正在使用XDocument加载和保存配置文件.大部分时间它都能正常工作,但有些情况(看似随机)会在最后一个标记之后附加额外信息.这是发生了什么的要点.
配置文件预运行:
<?xml version="1.0" encoding="us-ascii"?>
<local>
</local>
Run Code Online (Sandbox Code Playgroud)
码:
XDocument config = new XDocument();
config = XDocument.Load(new FileStream(@"c:\foo.xml", FileMode.Open, FileAccess.Read));
XElement fileEle = config.Root.Element("files");
XElement statsEle = new XElement("stats");
statsEle.Add(new XElement("one", "two"));
statsEle.Add(new XElement("three", "four"));
.
.
.
fileEle.Add(statsEle);
config.Save(new FileStream(@"c:\foo.xml", FileMode.Create, FileAccess.Write), SaveOptions.None);
Run Code Online (Sandbox Code Playgroud)
配置文件运行后:
<?xml version="1.0" encoding="us-ascii"?>
<local>
<files>
<one>two</one>
<three>four</three>
</files>
</local>s>
</local>
Run Code Online (Sandbox Code Playgroud)
有什么建议?不知道为什么要添加额外的字符.有时它是额外的标签,有时它是不同的字符,有时它可以正常工作.我尝试使用不同的方法(XMLReader等)加载/保存,以不同的方式添加XML标记.在X运行之后它们都产生相同的错误.谢谢您的帮助!