HttpUtility not recognised in .Net 4.5

Marnus_Steyn picture Marnus_Steyn · Jan 12, 2015 · Viewed 56.9k times · Source

I Developed a WinForm application in with the target framework set to .net 4.0, now I wish to add to a project that has it's target framework set to .net 4.5. After I added the 4.0 WinForm application to my 4.5 project I keep getting the an error on my HttpUtility object.

 data += "&batch_data=" + HttpUtility.UrlEncode(batch, System.Text.Encoding.GetEncoding("ISO-8859-1"));

"The name 'HttpUtility' does not exist in the current context"

I did include the System.Web namespace where the HttpUtility is located.

Visual Studio Error:

CS0234 The type or namespace name 'HttpUtility' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

Answer

giammin picture giammin · Jan 12, 2015

The problem is somewhere else.

As you can see in MSDN the HttpUtility class is present in System.Web in .NET Framework 4.5.

You're probably targeting the Client Profile: target the full framework in Project Properties. Otherwise:

  • either you did not add the right using statement using System.Web;
  • or you did not add the reference to System.Web.dll in the project.