Results 1 to 5 of 5

Thread: [RESOLVED] Type Expected although i import the namespace

  1. #1
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 10
    Location
    MSDN Library
    Posts
    256

    Resolved [RESOLVED] Type Expected although i import the namespace

    hello guys just wanna ask why i it gives me an error of type expected although i import the namespace of the required class..

    this is my code

    Code:
     dim request as HttpWebRequest = Directcast(WebRequest.Create(url),HttpWebRequest)
    why it gives me an error in HttpWebRequest it said that type expected eventhough i Import System.net
    i always need to complete the HttpWebRequest to this System.net.HttpWebRequest
    I also try to add the System.net Reference using the taskbar.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,834

    Re: Type Expected although i import the namespace

    Obviously the reference is useless because, as the documentation (which I'm sure you've read) states, the HttpWebRequest class is defined in the System.dll assembly, which you should find is referenced by default. If you have a reference to that assembly and you've imported the System.Net namespace then that should be all you need to do. Either something is broken or there's something you're not telling us. I'd be interested to see a screenshot of your code window showing that file. Can you attach one?

  3. #3
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 10
    Location
    MSDN Library
    Posts
    256

    Re: Type Expected although i import the namespace

    Quote Originally Posted by jmcilhinney View Post
    Obviously the reference is useless because, as the documentation (which I'm sure you've read) states, the HttpWebRequest class is defined in the System.dll assembly, which you should find is referenced by default. If you have a reference to that assembly and you've imported the System.Net namespace then that should be all you need to do. Either something is broken or there's something you're not telling us. I'd be interested to see a screenshot of your code window showing that file. Can you attach one?
    thanks for the reply JM Yeah i read the documentation that's why i import the system.net

    this is the screenshot the coding is not finish.

    Name:  FWSkm.png
Views: 42
Size:  182.2 KB

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,834

    Re: Type Expected although i import the namespace

    Right then, so what you weren't telling us is that your project is named HttpWebRequest. That means that the root namespace of your project is also named HttpWebRequest. When you type just that into your code, the compiler interprets it to be the root namespace of your project, not the class from the System.Net namespace. The logical thing to do is to give your projects proper names. In this case it could be something like "HttpWebRequest Demo" or "HttpWebRequest Test" if that's what the project is actually for. If it's a real project then give it a name that reflects its purpose, not what class it is using. For real projects it's also good to choose a "company name" and use that all the time. For instance, if I was creating a project that demonstrated using the HttpWebRequest class I might name it Wunnell.HttpWebRequestDemo.

    In the short term, go into the project properties and change the root namespace to something other than the name of an existing type or else fully qualify that type in your code.

  5. #5
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 10
    Location
    MSDN Library
    Posts
    256

    Re: Type Expected although i import the namespace

    Quote Originally Posted by jmcilhinney View Post
    Right then, so what you weren't telling us is that your project is named HttpWebRequest. That means that the root namespace of your project is also named HttpWebRequest. When you type just that into your code, the compiler interprets it to be the root namespace of your project, not the class from the System.Net namespace. The logical thing to do is to give your projects proper names. In this case it could be something like "HttpWebRequest Demo" or "HttpWebRequest Test" if that's what the project is actually for. If it's a real project then give it a name that reflects its purpose, not what class it is using. For real projects it's also good to choose a "company name" and use that all the time. For instance, if I was creating a project that demonstrated using the HttpWebRequest class I might name it Wunnell.HttpWebRequestDemo.

    In the short term, go into the project properties and change the root namespace to something other than the name of an existing type or else fully qualify that type in your code.
    Thanks for the help JM i thought i have missing a code but it just the name of the project. thanks again now i have a new lesson learned

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •