I'm new to .NET and having a difficult time deciphering when to use namespaces and where to place "using" clauses. For this one project, I'm trying to develop a .NET page within a web application that has 99% of the pages written in Classic ASP. I started by creating a C# website in MS Visual Web Developer 2010 Express. Within that website, I created a web form. So far, so good. To add to the confusion, let's inject another unfamiliar concept to the mix - a web service - 2 of them to be exact. Let's call them navCustomer and navShipTo. The name of the website is Registration, so I guess that's the namespace - yes/no?

The first line of the web form aspx file, Default2.aspx, is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Registration.Default2" %>

Here are the first few lines of Default2.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Mail;
using System.Net;

namespace Registration
using navCustomer;
using navShipTo;

public partial class Default2 : System.Web.UI.Page

when I build and run it from within the Visual IDE, it runs great. When I try to open the code from the browser through normal website navigation, I get this error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'navCustomer' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 14: namespace Registration
Line 15: {
Line 16: using navCustomer;
Line 17: using navShipTo;
Line 18:

It ain't right, I tell ya'! Please help.

5 Years
Discussion Span
Last Post by hericles

There is a little more to using a web service than dropping in a using statement. Is it a web service you are trying to connect to or a DLL component?
Using allows you to reference assemblies that may not be part of your default application (for example to use MySql databases you need to add a reference to the correct DLL and add the using mysql.data.client line).
If you are trying to connect to a web service it might pay to google a tutorial on how to do it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.