无法从程序集“System.Web”加载类型“System.Web.HttpContext”

时间:2011-02-07 18:41:37

标签: c# .net

System.TypeLoadException:无法从程序集'System.Web,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'加载类型'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 个答案:

答案 0 :(得分:3)

当然,如果您不在Web应用程序中,则无法使用HttpContext.Current!

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

答案 1 :(得分:0)

另一个问题是,免费社区版本似乎只能在.NET Framework中运行,而在.NET Core中则不能。