未能加载类型" System.Web.HttpContext"从装配"的System.Web"加载、类型、QUOT、HttpContext

2023-09-04 06:24:57 作者:男生拽,照样甩

System.TypeLoadException:未能从程序集加载类型System.Web.HttpContext''System.Web程序,版本= 2.0.0.0,文化=中性公钥= b03f5f7f11d50a3a

 使用系统;
System.Collections中使用;
使用System.Collections.Generic;
使用的System.Web;
使用System.Xml.Linq的;

公共类示例:
{
的XDocument DOC = XDocument.Load(System.Web.HttpContext.Current.Server.MapPath(〜/的example.xml));
}
 

解决方案

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

您可以检查是否System.Web.HttpContext.Current为空或不是,它是只适用于网页或Web服务。

配好了JDK,为什么找不到或者无法加载主类

System.TypeLoadException: Could not load type 'System.Web.HttpContext' from assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

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"));
}

解决方案

Of course, if you are not in a web application, no way you can use the HttpContext.Current !

you can check if System.Web.HttpContext.Current is null or not, it's available only in web pages or web services.