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"));
}
Run Code Online (Sandbox Code Playgroud)
另一个问题是,免费社区版本似乎只能在 .NET Framework 中运行,而不能在 .NET Core 中运行。
当然,如果您不在 Web 应用程序中,则无法使用 HttpContext.Current !
您可以检查 System.Web.HttpContext.Current 是否为 null,它仅在网页或 Web 服务中可用。
| 归档时间: |
|
| 查看次数: |
14333 次 |
| 最近记录: |