Net not found in System Namespace

Started by
13 comments, last by gan 15 years, 7 months ago
I get this error: error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?) From this line:
using System.Net;
How do I fix this?
Advertisement
As the error message hints, you need to actually reference the assembly (the actual DLL). Right click 'References', click 'Add', and scroll until you find System.Net (assuming you're using VC#).
[TheUnbeliever]
Ok, I did that, but now I'm getting the same error except with HttpWebRequest, WebRequest, and HttpWebResponse.

I get the error here:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.espn.com");        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
I found you have used "using System.Net;" before, you should not have any error by now, if you have added the reference like what TheUnbeliever told you. What kind of app(console, winform, ...) you are building? What error did you get?
Is the line:
using System.Net;


in the same code file as the other code you posted? If not, you'll need to add the 'using' statement to that file too. If so, I'm not sure what the problem is - you could always just use the full names (System.Net.HttpWebRequest etc) in the meantime.
Yes, I do have that line in my code.
The whole code:
using System;using System.IO;using System.Net;using System.Text;class Internet{    static void Main(string[] args)    {       StringBuilder sb = new StringBuilder();        byte[] buf = new byte[8192];        System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.espn.com");        System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();        Stream refStream = response.GetResponseStream();        string tempString = null;        int count = 0;        do        {            count = refStream.Read(buf, 0, buf.Length);            if (count != 0)            {                tempString = Encoding.ASCII.GetString(buf, 0, count);                sb.Append(tempString);            }        }        while (count > 0);        Console.WriteLine(sb.ToString());    }}


And the error:
Internet.cs(12,20): error CS0234: The type or namespace name 'HttpWebRequest' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
Internet.cs(12,57): error CS0234: The type or namespace name 'HttpWebRequest' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
Internet.cs(12,83): error CS0234: The type or namespace name 'WebRequest' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
Internet.cs(13,20): error CS0234: The type or namespace name 'HttpWebResponse' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
Internet.cs(13,59): error CS0234: The type or namespace name 'HttpWebResponse' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)

Can you post the contents of your .csproj file?

are you running in from VS2005/VS2003 IDE? I did on both with console app and working fine, even without adding reference.

Or can you try run in from compiler:
1) Open: "Microsoft Visual Studio 2005">"Visual Studio Tools">"Visual Studio 2005 Command Prompt"
2) change to your source directory, using: "cd"
3) type (without quotes; replace with your C# file name): "csc Program.cs"
you will get:
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1433for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

and a file "Program.exe" produced.

4) type (without quotes; this might take long time to execute since html parsing happening): "Program"
and I get this:

...s_omni.prop25 = "none";if(typeof(omniRegStatus) != "undefined" && omniRegStatus != "") s_omni.prop29=omniRegStatus;s_omni.hier1 = "home";s_omni.eVar9 = "en";s_omni.eVar13 = "home:frontpage";s_omni.eVar19 = "none";hbxparams = "{pageName=ESPN+Front+Page, category=/gen, premium=, crossgrid=, contentSection=sports, hasAccess=, columnist=, automated=N, username=}";anDebugCase = "v23May08.0.root-gen:page-frontpage:";/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/var s_code=s_omni.t();if(s_code)document.write(s_code)//--></script><!-- End SiteCatalyst code version: H.15.1. --><script language="JavaScript" src="http://assets.espn.go.com/insertfiles/javascript/wa/analytics.js"></script><!--begin revenueScience--><!-- Blank --><script language="javascript" type="text/javascript" src="http://log.go.com/log?ft=j&amp;srvc=sz&amp;addata=1184:53156:431649:56219|1233:::|1237:53156::|1433:53156:431939:53156|1034:183:227005:65|1149:::|1427:56422:388907:56422|1643:53156:417883:53156|2398:53156:431591:53156|2544:53156::&amp;target=6457;4492;389;&amp;method=GET&amp;cap=&amp;svr=espn.go.com&amp;host=espn.go.com&amp;guid=FAA69292-6E5F-4D67-B97E-55EA03E651E7&amp;sf="></script>
Quote:Original post by mutex
Can you post the contents of your .csproj file?

What does this mean? I thought that was the project file, so when I open it up I see the source I posted before.

And I'm using VS 2008, but I did try what gan said, and it worked! However, I'd like to find a way for it to work in VS. Any ideas?
Quote:Original post by NecoSpes
Quote:Original post by mutex
Can you post the contents of your .csproj file?

What does this mean? I thought that was the project file, so when I open it up I see the source I posted before.

And I'm using VS 2008, but I did try what gan said, and it worked! However, I'd like to find a way for it to work in VS. Any ideas?
The .csproj file lives in the directory of your project. If your project is named Foo, then you'll typically have a Foo.csproj file. Open it in Notepad and post it here; that should help determine whether you have the proper assembly references.

This topic is closed to new replies.

Advertisement