Chris
Chris

Reputation: 207

Could not load type "System.Web.HttpContext" from assembly "System.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"));
}

Upvotes: 11

Views: 29136

Answers (2)

Joshua G
Joshua G

Reputation: 2136

Another issue is that the free community version seems to only work in .NET Framework and not .NET Core sadly.

Upvotes: 5

Davide Piras
Davide Piras

Reputation: 44595

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.

Upvotes: 5

Related Questions