473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Option Strict and WebRequest object

This line raises a precompiler error when Option Strict is turned on:
Dim objRequest As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create(m_SearchURL)

The error:

Option Strict On disallows implicit conversions from 'System.Net.WebRequest'
to 'System.Net.HttpWebRequest'.

This is very confusing to me. Why would I need to cast this from WebRequest
if HttpWebRequest is its own object?
Nov 20 '05 #1
3 3757
"Elliot M. Rodriguez" <el**************@hotmail.spam.com> schrieb
This line raises a precompiler error when Option Strict is turned
on: Dim objRequest As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create(m_SearchURL)

The error:

Option Strict On disallows implicit conversions from
'System.Net.WebRequest' to 'System.Net.HttpWebRequest'.

This is very confusing to me. Why would I need to cast this from
WebRequest if HttpWebRequest is its own object?


"...is it's own object"??

Not every object/class derived from WebRequest is a HttpWebRequest object.
As the docs say, the Create method can either return a HttpWebRequest object
or a FileWebRequest object. If you are not sure which type is returned,
declare objRequest As WebRequest. In addition, you can check the type and
assign the type casted reference to a variable declared as HttpWebRequest or
FileWebRequest, but only if you really need to distinguish because you want
to use specific members. You can skip the check if you are sure that it only
will return one of both types:

objRequest = directcast( _
HttpWebRequest.Create(m_SearchURL), HttpWebRequest _
)
--
Armin

Nov 20 '05 #2
Armin:

I need to improve on RTFM before I post. Thank you for clarifying this for
me. I ended up using CType to cast it to an HttpWebRequest object.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Elliot M. Rodriguez" <el**************@hotmail.spam.com> schrieb
This line raises a precompiler error when Option Strict is turned
on: Dim objRequest As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create(m_SearchURL)

The error:

Option Strict On disallows implicit conversions from
'System.Net.WebRequest' to 'System.Net.HttpWebRequest'.

This is very confusing to me. Why would I need to cast this from
WebRequest if HttpWebRequest is its own object?
"...is it's own object"??

Not every object/class derived from WebRequest is a HttpWebRequest object.
As the docs say, the Create method can either return a HttpWebRequest

object or a FileWebRequest object. If you are not sure which type is returned,
declare objRequest As WebRequest. In addition, you can check the type and
assign the type casted reference to a variable declared as HttpWebRequest or FileWebRequest, but only if you really need to distinguish because you want to use specific members. You can skip the check if you are sure that it only will return one of both types:

objRequest = directcast( _
HttpWebRequest.Create(m_SearchURL), HttpWebRequest _
)
--
Armin

Nov 20 '05 #3
"Elliot M. Rodriguez" <el**************@hotmail.spam.com> schrieb
Armin:

I need to improve on RTFM before I post. Thank you for clarifying
this for me. I ended up using CType to cast it to an HttpWebRequest
object.


Are you sure a HttpWebRequest object is returned? ;-) If you are, DirectCast
is faster.
--
Armin

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: droope | last post by:
I have a routine that does a standard comparison that I pass two objects to Private Function ColumnEqual(ByVal A As Object, ByVal B As Object) As Boolea ' Compares two values to determine if...
1
by: Eduardo Garcia-Prieto | last post by:
I have come accross a problem in using the Interlocked.Exchange(Object, Object) method while using Option Strict On in my project. I have a private class structure variable which can be updated...
8
by: Rich | last post by:
Hello, If I leave Option Strict Off I can use the following syntax to read data from a Lotus Notes application (a NotesViewEntry object represents a row of data from a Lotus Notes View - like a...
13
by: Shannon Richards | last post by:
Hello: I have a problem using ByRef arguments with Option Strict ON. I have built a generic sub procedure "ChangeValue()" to change the value of an argument if the new value is not the same as the...
4
by: jmhmaine | last post by:
The following code works when Option Strict is off: Dim thumbSize As New Size thumbSize = CType(NewthumbSize(g.Width, g.Height, 100), System.Drawing.Size) Dim imgThumbOutput As New Bitmap(g,...
4
by: Howard Kaikow | last post by:
I am trying to retrive some WMI properties using Option Strict On. This requires the use of InvokeMember. I know that there are alternative ways to get the values, but I want to learn how to...
9
by: YYZ | last post by:
After reading many messages in this group, it seems that the preferred setting for this is ON. Okay, I did that in my project (first with ..Net -- long time VB6 developer) and now a bunch of...
15
by: guy | last post by:
when i first started using .net (beta 1) i came across option strict and thought hey this could be really good, and since then have always turned it on, most people here seem to agree that this is...
4
by: John | last post by:
Hi I have a vs 2003 project which I have just imported into vs 2005. Now I am getting the "Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.