2011-02-07 102 views
0

System.TypeLoadException:无法从程序集“System.Web,Version = 2.0.0.0,Culture”中加载类型“System.Web.HttpContext” =中立,PublicKeyToken = b03f5f7f11d50a3a'。无法从程序集“System.Web”加载类型“System.Web.HttpContext”

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Web; 
using System.Xml.Linq; 

public class Example : 
{ 
XDocument doc = XDocument.Load(System.Web.HttpContext.Current.Server.MapPath("~/example.xml")); 
} 
+2

你有没有参考system.web? – 2011-02-07 18:43:49

+0

看看InnerException。 – 2011-02-07 18:44:40

回答

2

当然,如果你是不是在一个Web应用程序,没有办法,你可以使用HttpContext.Current!

您可以检查System.Web.HttpContext.Current是否为null,它只能在网页或Web服务中使用。

相关问题