C# 无法加载类型“;System.Web.HttpContext“;“来自组件”;System.Web”的缩写;
System.TypeLoadException:无法从程序集“System.Web,版本=2.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Web.HttpContext”C# 无法加载类型“;System.Web.HttpContext“;“来自组件”;System.Web”的缩写;,c#,.net,C#,.net,System.TypeLoadException:无法从程序集“System.Web,版本=2.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Web.HttpContext” using System; using System.Collections; using System.Collections.Generic; using System.Web; using System.Xml.Linq; public class
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"));
}
当然,如果您不在web应用程序中,就无法使用HttpContext.Current
您可以检查System.Web.HttpContext.Current是否为null,它仅在网页或web服务中可用。另一个问题是,免费社区版本似乎只在.NET Framework中工作,而不是.NET Core。遗憾的是,您是否有system.web的引用?您应该接受答案,让人们知道您现在很好……接下来的问题是如何返回一个相对路径,而不必使用C#中的Server.MapPath。由于映射路径是相对于当前虚拟目录或网站的,因此在非web应用程序中使用它没有意义。如果您只是想在文件系统的任何位置将相对路径更改为绝对路径,那么Server.MapPath不是您所需要的。程序集“system.Web”中的“system.Web.HttpContext”不是Net Core 3.1的解决方案?