HttpContext not available in Class Library
Asked Answered
S

3

26

I am working on a project where I have a C# class library which needs to use the System.web.HttpContext. I've done this before in another project without problem but now its not working. I'm not sure what I am missing they're both targeting .net 3.5 and I've added the reference System.web and added the directive using System.web.

However, when I try and do HttpContext nothing is found. I've tried using the full path System.web.HttpContext but the only thing that comes up are 3 items related to ASP.

Below are screenshots from the working project intellisense and the non-working intellisense

Below is the working screenshot

working screenshot

and below is the non working screenshot

not working screenshot

Thanks for any help you can provide

Sayles answered 4/1, 2013 at 1:20 Comment(2)
Did you add a reference to the System.Web .Net assembly in your project?Maricruzmaridel
@Maricruzmaridel I did say in the question that I added the reference and the directiveSayles
D
36

This means that either you are using a Client Profile as the Target Framework or the reference to System.Web was not added correctly.

Disinter answered 4/1, 2013 at 1:27 Comment(2)
Thanks, I had it has a client profile by mistake, thought I'd changed it to the full version.Sayles
Just to note "Starting with the .NET Framework 4.5, the Client Profile is no longer available. The full re-distributable has been optimized for faster deployment and smaller disk space. You no longer have to decide whether to use the Client Profile or the full .NET Framework—just target the .NET Framework 4.5." .NET Framework Client Profile, August 2012Zorn
S
7

Despite your comment that you've added reference to System.Web to the project it is still most likely reason of what you are seeing.

The classes you see are coming from System.Dll, not System.Web.Dll.

Silkworm answered 4/1, 2013 at 1:31 Comment(0)
T
4

Just to add some input incase someone else gets hung up on this. If you are in a Unit test project or a Class Library that links back to an MVC project, you may have references to System.Web.Mvc. This DOES NOT INCLUDE System.Web. You must add both if you need something Mvc specific (like a SelectList) AND HttpContext

Treasurer answered 4/6, 2014 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.