Sign in to follow this  

Net not found in System Namespace

This topic is 3398 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

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
Here it is:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{017A53B5-8AB9-4C91-922D-60619739FCC0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Interweb</RootNamespace>
<AssemblyName>Interweb</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Compile Include="Internet.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
</Project>

Share this post


Link to post
Share on other sites
You're referencing the wrong assembly. HttpWebRequest etc are not defined in System.Net.dll, but in System.dll.

You can find this kind of information in the documentation:
HttpWebRequest

Quote:

HttpWebRequest Class
...
Provides an HTTP-specific implementation of the WebRequest class.
...
Namespace: System.Net
Assembly: System (in System.dll)

Share this post


Link to post
Share on other sites
VizOne is correct, i missed it.
just curious(You seems knows nothing about MSBuild.) how you create your C# project, normally you will have these from VS2008 IDE console apps generated:

<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>



Share this post


Link to post
Share on other sites
Quote:
Original post by gan
VizOne is correct, i missed it.
just curious(You seems knows nothing about MSBuild.) how you create your C# project, normally you will have these from VS2008 IDE console apps generated:
*** Source Snippet Removed ***


Of course, you can also remove those references from the IDE, which is possibly what happened here.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Quote:
Original post by gan
VizOne is correct, i missed it.
just curious(You seems knows nothing about MSBuild.) how you create your C# project, normally you will have these from VS2008 IDE console apps generated:
*** Source Snippet Removed ***


Of course, you can also remove those references from the IDE, which is possibly what happened here.



I know. Just curious what drove him to do so :)
Whos knows, maybe he was doing some tutorials on MSBuild :)

Share this post


Link to post
Share on other sites

This topic is 3398 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this