Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The name 'HttpUtility' does not exist in the current context (winform)

Iget the following error:

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

I am building a winform app this my code using framework 4 client profile and I can't find the System.Web reference:

string longurl = "https://test.com/currentaccount/Pages/current.aspx";
                        var uriBuilder = new UriBuilder(longurl);
                        var query = HttpUtility.ParseQueryString(uriBuilder.Query);//error
                        query["ltFrom"] = FromDate;
                        query["ltTo"] = ToDate;
                        query["ltFilterSelected"] = "none";
                        uriBuilder.Query = query.ToString();
                        longurl = uriBuilder.ToString();

What is the problem?

like image 275
Vladimir Potapov Avatar asked Nov 25 '25 15:11

Vladimir Potapov


2 Answers

HttpUtility cannot be accepted with ClientProfile - change your .Net version to full.

like image 96
igofed Avatar answered Nov 27 '25 04:11

igofed


The project is set on Target Framework to: .net 4 client profile.

That's the problem. HttpUtility doesn't exist in the client profile. Target the full profile instead (and make sure you have a reference to System.Web.dll).

Compare the "Version information" line from the above documentation:

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

with that of (say) System.String:

.

NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client Profile
Supported in: 4, 3.5 SP1
Portable Class Library
Supported in: Portable Class Library
.NET for Windows Store apps
Supported in: Windows 8

ref: Im getting error on visual studio 2010: The type or namespace name 'HttpUtility' does not exist

like image 22
Vijay Singh Rana Avatar answered Nov 27 '25 04:11

Vijay Singh Rana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!