Jump to content
  • Advertisement
Sign in to follow this  
NecoSpes

Net not found in System Namespace

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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#).

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?)

Share this post


Link to post
Share on other sites
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.1433
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (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=om
niRegStatus;
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=, con
tentSection=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/javascr
ipt/wa/analytics.js"></script>
<!--begin revenueScience-->

<!-- Blank --><script language="javascript" type="text/javascript" src="http://l
og.go.com/log?ft=j&amp;srvc=sz&amp;addata=1184:53156:431649:56219|1233:::|1237:5
3156::|1433:53156:431939:53156|1034:183:227005:65|1149:::|1427:56422:388907:5642
2|1643:53156:417883:53156|2398:53156:431591:53156|2544:53156::&amp;target=6457;4
492;389;&amp;method=GET&amp;cap=&amp;svr=espn.go.com&amp;host=espn.go.com&amp;gu
id=FAA69292-6E5F-4D67-B97E-55EA03E651E7&amp;sf="></script>

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!