XDocument类使用错误

zhangfengyi 2010-02-07 02:26:23
使用XDocument时显示上下文不存在名称XDocument,查MSDN,需要引用using System.Xml.linq; 引用这个时显示"命名空间System.Xml中不存在linq",请问这个应该怎么处理?
...全文
272 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Goldfire_001 2010-02-08
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhangfengyi 的回复:]
Goldfire_001(菜菜的高手)这段代码怎样调用
[/Quote]

啊,童鞋,直接调用静态方法么。这就是个Helper类么。
Assembly assembly = LoadAssemblyFromXap(e.Result, "ExternalProject.dll");//other project name.dll

替换你代码里的这句。
List<Assembly> assemblyList = AssemblyLoader.LoadAssembly(e.Result);

然后遍历自己去找你需要的Assembly么。
zhangfengyi 2010-02-08
  • 打赏
  • 举报
回复
Goldfire_001(菜菜的高手)这段代码怎样调用
zhangfengyi 2010-02-08
  • 打赏
  • 举报
回复
public class AssemblyLoader
{
public static List<Assembly> LoadAssembly(Stream packageStream)
{
Stream stream = Application.GetResourceStream(
new StreamResourceInfo(packageStream, null),
new Uri("AppManifest.xaml", UriKind.Relative)).Stream;
if (stream == null)
{
throw new ArgumentException("Can not get file \"AppManifest.xaml\" from test assembly xap");
}
string appManifestString = new StreamReader(stream).ReadToEnd();
XElement deploymentRoot = XDocument.Parse(appManifestString).Root;
List<XElement> assemblyParts = new List<XElement>(deploymentRoot.Descendants().Elements());

List<Assembly> assemblyList = new List<Assembly>();
foreach (XElement assemblyPart in assemblyParts)
{
StreamResourceInfo streamInfo = Application.GetResourceStream(
new StreamResourceInfo(packageStream, "application/binary"),
new Uri(assemblyPart.Attribute("Source").Value, UriKind.Relative));
if (assemblyPart != null)
{
assemblyList.Add(new AssemblyPart().Load(streamInfo.Stream));
}
}
return assemblyList;
}
}
Goldfire_001 2010-02-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhangfengyi 的回复:]
2.0与3.5有什么区别吗,加载2.0就行,3.5不行
[/Quote]

区别还是有滴吧。

大版本更替,当然有区别啦。。。具体吗。问Google啦。。
zhangfengyi 2010-02-08
  • 打赏
  • 举报
回复
2.0与3.5有什么区别吗,加载2.0就行,3.5不行
Goldfire_001 2010-02-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhangfengyi 的回复:]
添加引用也不行,怎么办啊
[/Quote]

检查引用版本。
zhangfengyi 2010-02-08
  • 打赏
  • 举报
回复
添加引用也不行,怎么办啊
jv9 2010-02-08
  • 打赏
  • 举报
回复
默认项目引用system.xml,但是XDocument在system.xml.linq命名空间中,所以你需要添加新的引用。

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧