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

Harreni
Harreni used Ask the Experts™
on
Hi Experts,

I'm using visual studio 2012 and just started building my first web service. When I tried to build my website that host a simple web service, I keep getting this error :
Error1 The type or namespace name 'localhost' could not be found (are you missing a using directive or an assembly reference?)      C:\Users\IT\Documents\Visual Studio 2012\WebSites\Temprature\Temprature.aspx.cs      22 9)
and the code snippet that has this error is :

sing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Temprature : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        localhost.Convert wsConvert = new localhost.Convert();
        double temperature =
        System.Convert.ToDouble(TemperatureTextbox.Text);
        FahrenheitLabel.Text = "Fahrenheit To Celsius = " +
        wsConvert.FahrenheitToCelsius(temperature).ToString();
        CelsiusLabel.Text = "Celsius To Fahrenheit = " +
        wsConvert.CelsiusToFahrenheit(temperature).ToString();
    }
}

Open in new window


So, please guide me to solve this issue.

Thanks a lot in advance.
Harreni
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Click on "localhost". Next, push Ctrl and period keys. You should get a popup offering suggestions on how to fix. One of those suggestions should be to import the missing namespace. Select that option.

Author

Commented:
Thanks a lot käµfm³d for guiding and helping me.
I did what you suggest me to do and I got a long list but I don't know which one is correct.
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
What does the list look like? Can you screenshot it?
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
When you add a Web Reference to your project, it will create the namespace based on your server name, so it will only be called localhost if that's your server name. If you have it named as anything else, then use that name instead.

Check the namespace of your reference - the file will be somewhere in the App_WebReferences folder.
Steven KribbeSoftware Engineer
Commented:
remove the localhost. You can just use Convert

Author

Commented:
Thanks a lot käµfm³d, Chris and Steven you're all helped me.
I forgot to add "using System.Web.Services;" to my name spaces list

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial