未能加载类型" System.Web.HttpContext"从装配"的System.Web" [英] Could not load type "System.Web.HttpContext" from assembly "System.Web"

查看:311
本文介绍了未能加载类型" System.Web.HttpContext"从装配"的System.Web"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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服务。

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.

这篇关于未能加载类型" System.Web.HttpContext"从装配"的System.Web"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆