Can't Access HttpUtility

robertb_NZ

Well-known member
Joined
May 11, 2010
Messages
146
Location
Auckland, New Zealand
Programming Experience
10+
I am using VS2010 with .NET Framework 4.0.

Project GDBChart. I had written this as part of the logic to pass parameters from ClickOnce to a Windows program through the query string . It all worked perfectly: -

Imports System.Deployment.Application
Imports System.Collections.Specialized
Imports System.Web
...
Dim NameValueTable As New NameValueCollection()
...
NameValueTable = HttpUtility.ParseQueryString(QueryString)

Project Jazz. I wanted to add the same feature to this project, so I copy/pasted the code. The VS2010 setup is identical. Yet now I get an error on the reference to HttpUtility: 'HttpUtility' is not declared. It may be inaccessible due to its protection level.

There are no messages on Imports System.Web

In project GDBChart, if I write System.web. then the next-level menu shows about 100 items, including HttpUtility. In project Jazz there are only 4 items.

I tried to find the answer on the web. Responses talked of ensuring that I was using the correct framework version. Both use 4.0. I can set the framework version to earlier frameworks when I start a new framework, but there is no option to change this on the application tab of projects' property pages. I was not offered the option of a Client Framework which some pages suggested was the problem.

What's my next move?
Thanks for any help, Robert.
 
What assembly is that class declared in? Have you referenced that assembly? I'll wager not. The MSDN documentation for every type specifies which assembly it's declared in and which namespace it's a member of. If you don't understand what assemblies and namespaces are, I suggest that you follow the Blog link in my signature below and check out my post on the subject.
 
The HttpUtility class is in namespace System.Web, assembly System.Web (In System.Web.dll). Hence my focus on System.Web in my post.

I have believed that if I write IMPORTS xxxx then that references assembly xxxx, and I don't need to add it to the list of project references explicitly. Is this wrong?

Looking at the References tab of the project properties:
Project GDBChart (which works): System.web is included, details: Type=.NET Version=2.0.0.0 Copy=False Path=C:\Windows\Microsoft.NET\Framework\v2.0.50727\system.web.dll
Project Jazz (doesn't work): Does not include System.web in the list of references.
In the section "Imported Namespaces", neither project has System.web checked.

In project Jazz I tried checking it, and then clicking [Add]. This displayed "Add reference", the .NET tab of which noted "Filtered to: .NET Framework 4.0 Client Profile". When I did the same in project GDBChart I saw that the .NET tab noted "Filtered to: .NET Framework 3.5".

This supports the first web page I looked up (c# - HttpUtility does not exist in the current context - Stack Overflow) which fingered this as the issue. However I couldn't apply its fix because I couldn't find anywhere to change the framework version in my project. As with this page
https://msdn.microsoft.com/en-us/library/bb398202.aspx#bkmk_existing
I was directed to the Application tab project's properties where it looked easy to change, but whereas the examples show a combo below Assembly Name labelled "Target Framework" allowing one to change the framework from ".NET 4.0 Client Profile" to ".NET 4.0", my Application tabs have "Application Type" in this position, and there's nowhere in the properties that I can change the framework.

I'm reluctant to upgrade to VS2015 right now, but is there an alternative?

Thanks, Robert.
 
I have believed that if I write IMPORTS xxxx then that references assembly xxxx, and I don't need to add it to the list of project references explicitly. Is this wrong?
You're importing namespaces, not assemblies. I wrote the blog post I referred to for a reason. Are you not reading it for a reason?
 
If I click "My Blog" it takes me to an article about Managing Data in Multiple Forms. "Defining and raising custom events" and "Why is my data not saved to my database" are equally irrelevant. The only link with an index, Beginner Tutorial, has nothing with a title indicating Namespaces and Assemblies.

Really, if you thought I should read a particular article, why didn't you do what anybody being helpful would have done and given me the URL? Then I might have read it. But I'm hardly likely to click around a blog of what appear to be irrelevant articles without an index when I think that I understand about namespaces and assemblies after developing with .NET since 2006.

The fact remains that in all previous occasions VS has given me error messages when I need to explicitly include something (like a 3rd party class) to make it work in my project. Based on the web pages I found when researching this problem I believe that the issue is one of the framework version, and I need to find a way of changing this from 4.0 Client Filter to 4.0.

Robert
 
You clearly don't understand assemblies and namespaces if you think that importing a namespace means that you don't need to reference an assembly. That Blog link takes you to the home page for my blog, which shows the most recent article first. There's an index on the right of the page and it would have taken you about 20 seconds to find the relevant article had you made the effort to look. If it's not important enough to you to make that effort to help yourself, why should it be important to me. The information is there if you want it but you've guaranteed that I won't provide any more help than that.
 
Prompted by the above I now HAVE found the article, but (not counting my previous clicking around on earlier visits) this took me 8 clicks because there's no index, no search facility, just an archive of articles in sequential order. All you would have had to do to have been helpful would have been to give the url, John McIlhinney .NUT: Referencing Assemblies and Importing Namespaces

I read your paper but it doesn't help. The situation is exactly as I described in my 2nd post in this thread. Unfortunately you don't appear to have read read this post beyond a minor question: at this point you seem to have decided that I was too ignorant or lazy to bother with.

Please go back and re-read my 2nd post and try to think about helping me instead of directing me to papers that don't help and tell me little that I don't already know. To summarize what I wrote in that post: when I click [Add] the list of references is "Filtered to .NET Framework 4 Client Profile", and this does NOT INCLUDE System.Web. As I had correctly surmised from my web research before first posting to this forum, the issue is that I need to change this, but I can't find how to do this.

By the way, it's not unreasonable to believe that Imports xxxx would bring in BOTH the reference and the namespace, since this is what APPEARS to happen, it is definitely what happens in some other contexts like Link-editing an IBM mainframe program, and from the descriptions of VS2015 and .NET 2.6 I believe that it's what happens now.

Robert
 
Imports is just a "shortcut" for type names, allowing to omit the namespace if there is no ambiguity. So you can write for example Button instead of System.Windows.Forms.Button. It is like telling compiler that "if I'm not precise about the types used in code then have a look in these places and see if you know which I mean". Imports statement can also define an alias for a namespace.

To use a type (or even use a namespace name) it must be known to assembly, either it is declared within assembly or by a reference to an external assembly. Compiler is helpful if namespace is completely unknown, it will ask "are you missing an assembly reference?".

In Compile tab of project settings you can change advanced setting of framework, to change from .Net 4 Client to just .Net 4 (full).
 
Problem Solved!

In Compile tab of project settings you can change advanced setting of framework, to change from .Net 4 Client to just .Net 4 (full).

Fantastic, this is what I needed to know. I changed the framework to ".Net Frameword 4.0", then I was able to add System.web to the references, and all is now as it should be. Thank you.
 
Back
Top