views:

1447

answers:

5

I'd like to use HttpUtility.UrlEncode in a console application, VB.NET, VS 2010 Beta 2.

System.Web.HttpUtility.UrlEncode(item)

Error message: 'HttpUtility' is not a member of 'Web'.

In this question Anjisan suggests to add a reference to System.Web, as follows:

  1. In your solution explorer, right click on references
  2. Choose "add reference"
  3. In the "Add Reference" dialog box, use the .NET tab
  4. Scroll down to System.Web, select that, and hit ok

However, I don't have a System.Web entry at that location.

A: 

You need to add a reference to both System.Web and System.Web.Extensions.

Jarrett Meyer
+5  A: 

System.Web is there, but seems Visual Studio doesn't sort by name by default. You'll need to click Component name column to get that list sorted.

I was able to run this code:

Console.WriteLine(System.Web.HttpUtility.UrlEncode(" ")); // +

Just adding a System.Web reference, without System.Web.Extensions.

Rubens Farias
I still can't find it. I only have "System.Web.ApplicationServices" and "System.Web.Services". Which version of Visual Studio / .NET are you using?
iar
I tested with VS2010b2; did you sorted that list? What project type, framework version did you defined?
Rubens Farias
I did sort the list. It's a console application. Framework 4.0, runtime version v4.0.21006.
iar
You should to replace your target framework from `.NET Framework 4 Client Profile` to `.NET Framework 4`; go to `Project, {0} Properties..., Application tab`
Rubens Farias
You are a hero. I have no idea how this target framework was set to "the wrong one", but anyway it works now. THANK YOU VERY MUCH.
iar
In visual studio 2010, the default project is "4.0 client profile", so it's not 'wrong'.
FrederikB
+2  A: 

@iar, the framework was not set to "the wrong one". Console and Windows applications (there are more) target .NET Framework 4 Client Profile by default in Visual Studio 2010. This is by design. And it happens when you target ".NET Framework 4" in the New Project Dialog. Why it didn't find System.Web.dll is because it is not part of the .NET Framework 4 Client Profile, so the project system cannot find it and issues a warning during build-time (which you probably ignored, granting you referenced System.Web.dll). You won't find System.Web.dll in the .NET tab in Add Reference dialog also, because that list is filtered according to the targeted framework.

Ion Todirel
+3  A: 

Make sure your target framework is ".NET Framework 4" not ".NET Framework 4 Client Profile".

rushonerok
A: 

Changing the project's Target Framework from ".NET Framework 4 Client Profile" to ".NET Framework 4.0" helped me, with .NET Framework 4 Client Profile as Target framework I was able to add System.Web 2.0 version by Browsing to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 from Add reference window but doing the same for System.Web 4.0 dll gave a warning.

Kiran Bheemarti