ChatGPT解决这个技术问题 Extra ChatGPT

HttpUtility does not exist in the current context

I get this error when compiling a C# application. Looks like a trivial error, but I can't get around it.

My setup is Windows 7 64 bit. Visual-Studio 2010 C# express B2Rel.

I added a reference to System.Web.dll located at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0, but it has a yellow exclamation symbol and I still get the above error. I also have the using System.Web declaration.

What am I doing wrong?

Update: After getting the prompt answer pointing me at the root cause, I searched a bit in Google to where it states that System.Web.dll is for the full framework. I did not find such a reference.
For newbies like me, this blog summarizes the difference between the frameworks (client and full) nicely. I could not find a spot that says whether a certain Dll is supported in the client framework or not. I guess the exclamation mark in Visual Studio should be the first signal...

Are you targeting the Client Profile?

M
Matt

You need to add the System.Web reference;

Right click the "Reference" in the Solution Explorer Choose "Add Reference" Check the ".NET" tab is selected. Search for, and add "System.Web".


VS2012 Console App using targeting .NET Framework 4.5. This resolved.
Even with the target, only adding reference worked for me. Thanks lxk613
Bingo! This is the answer.
My solution Explorer tree does not contain "Reference"
if you are using Azure functions, add #r "System.Web" on top of your file
D
David Ferenczy Rogožan

You're probably targeting the Client Profile, in which System.Web.dll is not available.

You can target the full framework in project's Properties.


Bingo! where is that specified? Where was I supposed to read this? Thanks.
I've set full framework in Project Properties, yet the problem exists.
@AlexJolig: Make sure you have the reference and the namespace.
@blackholeearth0_gmail: What's the problem? What are you targetting?
i converted project from .net2 to .net4. just changing Target Framework didnt' fix problem. i needed to add the dll, too. that is explained better in at lxk613's answer , and shows what i need to do to fix the problem .
S
Someone Somewhere

SLaks has the right answer... but let me be a bit more specific for people, like me, who are annoyed by this and can't find it right away :

Project -> Properties -> Application -> Target Framework -> select ".Net Framework 4"

the project will then save and reload.


I had the error even WITH the full framework targeted! Adding System.Web.dll as a reference worked though.
And obviously make sure to add System.Web or System.Web.Mvc to the file in question too.
S
Shaihi

In order to resolve this, Kindly go to the below path Project-->Properties-->Application-->TargetFramework and change the Framework to ".NET Framework 4". Once you do this, the project will close and re-open. This should solve the error

(but for some reason @Karan Modi's answer does not...)

next right-click the references tab in the solution explorer and choose add reference,

choose "System.Web"

(declaring the namespace directly by "using System.Web;" doesnt seems to be enough...you have to add it to the solution explorer...i cant understand why - which is no surprise because i am a cobol programmer..


M
Maubeh

After following the answers above , and did

Project -> Properties -> Application -> Target Framework -> select ".Net Framework 4"

It still didn't work until I went to
Project -> Add Reference
And selected System.web. And everything worked link a charm.


Same solution has already been provided by someone, 2 years back. Please check the solutions before posting your own. The question is too old and the original poster is less likely to notice your response.
Seems like @lxk613's answer
K
Karan Modi

In order to resolve this, Kindly go to the below path

Project-->Properties-->Application-->TargetFramework

and change the Framework to ".NET Framework 4".

Once you do this, the project will close and re-open.

This should solve the error.


on Mac, Target Framework max (thanks to mono) is .NET 2. How can I solve on there?
J
Jon Egerton

Agrega System.web a las referencias del proyecto.

[Edit]

According to Google Translate, this translates to:

Add System.Web to the project references.


A
Ayo Adesina

Adding a reference to Sysem.Web.Dll did it for me.


S
Shaahin

I had the same problem what I did, I copied web.dll from Microsoft.NET framework, then paste in root of project, then add dll refrence to app, it worked


B
Bijay Budhathoki

It worked for by following process:

Add Reference:

system.net
system.web

also, include the namespace

using system.net
using system.web