Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I am trying to use the following code in my website
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
I am using visual studio 2012
I get the error that
VB
Error   1   The type or namespace name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)  

I know that i need to add a reference. I get problem while adding reference when i follow the following steps.
I right click on the site name in Solution explorer and click on add - click on reference. A dialogue box appears. i click on System.Net.Http and also click on System.Net.Http.WebRequest. The boxes are tick - marked. Then i press OK
I expect the reference to be added but i do not see any addition of reference and error continues to display.

Kindly help me advising what mistake i am making in adding reference.

Many thanks for your help
Posted

Right-click on HttpWebRequest and from the context-menu select Resolve. Under the resolve menu there will be an option for adding the correct using (using System.Net) so select that.
 
Share this answer
 
Comments
Member 10235977 2-Sep-15 11:20am    
Right click does not give any context menu. however moving mouse over HttpWebRequest shows the path for related dll file, which is available in program. I tried copying that file to Bib but it does not help. I have also tried adding references
System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"
System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A
System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"
But it does not accept the using directive
System.Net.Http.WebRequest

I continue getting the same error
F-ES Sitecore 2-Sep-15 11:24am    
As well as adding the reference you need to either use the class' full name (System.Net.HttpWebRequest) or use the class name only (HttpWebRequest) and have "using System.Net;" at the top of your cs file.

You're not explaining if it is adding the reference you can't do or if it is getting the code to work in the project.
HttpWebRequest is in System.Net, https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.110).aspx[^].

If you have that as a reference then add the using statement. You should also get a little blue (as I recall) underline underneath the beginning of the line of code where the error is. Hover over that, and it should suggest adding the using which you can just click it to do it for you.
 
Share this answer
 
Comments
Member 10235977 2-Sep-15 11:21am    
kindly see my comment under solution 1
ZurdoDev 2-Sep-15 11:24am    
Use the smart tool tip as I suggested.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900