473,395 Members | 1,457 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,395 software developers and data experts.

c# to vb.net conversion

This is driving me insane!
I'm trying to solve "The underlying connection was closed" issue when
using WSE 3.0 in VS2005.
I'm trying to convert the following c# code to vb.net:

(This is from:
http://weblogs.asp.net/jan/archive/2...08/128394.aspx)

Using System.Net;
Using System.Reflection;

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
PropertyInfo requestPropertyInfo = null;
WebRequest request = base.GetWebRequest(uri);
if (requestPropertyInfo==null)
requestPropertyInfo = request.GetType().GetProperty("Request");
// Retrieve underlying web request
HttpWebRequest webRequest =
(HttpWebRequest)requestPropertyInfo.GetValue(reque st, null);
webRequest.KeepAlive = false;
return request;
}
I've done this so far:

Imports System.Net
Imports System.Reflection

Protected Overloads Overrides Function GetWebRequest(ByVal uri As Uri)
As System.Net.WebRequest
Dim requestPropertyInfo As PropertyInfo = Nothing
Dim request As WebRequest = MyBase.GetWebRequest(uri)
If requestPropertyInfo Is Nothing Then
requestPropertyInfo =
request.GetType.GetProperty("Request")
End If
Dim webRequest As HttpWebRequest =
CType(requestPropertyInfo.GetValue(request, Nothing), HttpWebRequest)
webRequest.KeepAlive = False
Return request
End Function

When I run this i get the following error:

"System.NullReferenceException: Object reference not set to an instance
of an object."

This occurs on the following line:

Dim webRequest As HttpWebRequest =
CType(requestPropertyInfo.GetValue(request, Nothing), HttpWebRequest)

I think this is due to the "Nothing" being passed???

Does anyone know how to convert this? I've tried everything!
The parameter details are "index() As Object".

Any help would be much appreciated!!!

Jun 21 '06 #1
9 3716
"mcateer77" <bm******@gmail.com> schrieb:
I'm trying to solve "The underlying connection was closed" issue when
using WSE 3.0 in VS2005.
I'm trying to convert the following c# code to vb.net:


Your translation seems to be correct.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jun 21 '06 #2
Any idea why I'm getting this error?

Thks

Herfried K. Wagner [MVP] wrote:
"mcateer77" <bm******@gmail.com> schrieb:
I'm trying to solve "The underlying connection was closed" issue when
using WSE 3.0 in VS2005.
I'm trying to convert the following c# code to vb.net:


Your translation seems to be correct.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Jun 21 '06 #3
"mcateer77" <bm******@gmail.com> schrieb:
Any idea why I'm getting this error?


Could you post the complete exception message?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jun 21 '06 #4
Here you go:

System.NullReferenceException: Object reference not set to an instance
of an object.
at DPS.dpsauthentication.dpsauthentication.GetWebRequ est(Uri uri) in
C:\Documents and Settings\brianmcateer.BRANDON\My Documents\Visual
Studio Projects\DPS\dpsauthentication.vb:line 98
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)
at DPS.dpsauthentication.dpsauthentication.DPSrequest Token(Int32
version, String vendorID) in C:\Documents and
Settings\brianmcateer.BRANDON\My Documents\Visual Studio
Projects\DPS\dpsauthentication.vb:line 49
at DPS.Form1.Button1_Click(Object sender, EventArgs e) in
C:\Documents and Settings\brianmcateer.BRANDON\My Documents\Visual
Studio Projects\DPS\Form1.vb:line 94

Thanks!

Jun 21 '06 #5
Hello mcateer77,

Your translation is wrong. You can't Dim uri As Uri.

Here's the correct translation:

Imports System
Imports System.Net
Imports System.Reflection

Protected Overrides Function GetWebRequest(ByVal tURI As Uri) As System.Net.WebRequest

Dim tPropertyInfo As PropertyInfo = Nothing
Dim tRequest As WebRequest = MyBase.GetWebRequest(tURI)
Dim tRequestToo As WebRequest = Nothing

If Nothing Is tPropertyInfo Then
tPropertyInfo = tRequest.GetType.GetProperty("Request")
End If
tRequestToo = tPropertyInfo.GetValue(tRequest, Nothing)
tRequestToo.KeepAlive = False

Return tRequest

End Function

-Boo
This is driving me insane!
I'm trying to solve "The underlying connection was closed" issue when
using WSE 3.0 in VS2005.
I'm trying to convert the following c# code to vb.net:
(This is from:
http://weblogs.asp.net/jan/archive/2...08/128394.aspx)
Using System.Net;
Using System.Reflection;
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
PropertyInfo requestPropertyInfo = null;
WebRequest request = base.GetWebRequest(uri);
if (requestPropertyInfo==null)
requestPropertyInfo = request.GetType().GetProperty("Request");
// Retrieve underlying web request
HttpWebRequest webRequest =
(HttpWebRequest)requestPropertyInfo.GetValue(reque st, null);
webRequest.KeepAlive = false;
return request;
}
I've done this so far:

Imports System.Net
Imports System.Reflection
Protected Overloads Overrides Function GetWebRequest(ByVal uri As Uri)
As System.Net.WebRequest
Dim requestPropertyInfo As PropertyInfo = Nothing
Dim request As WebRequest = MyBase.GetWebRequest(uri)
If requestPropertyInfo Is Nothing Then
requestPropertyInfo =
request.GetType.GetProperty("Request")
End If
Dim webRequest As HttpWebRequest =
CType(requestPropertyInfo.GetValue(request, Nothing), HttpWebRequest)
webRequest.KeepAlive = False
Return request
End Function
When I run this i get the following error:

"System.NullReferenceException: Object reference not set to an
instance of an object."

This occurs on the following line:

Dim webRequest As HttpWebRequest =
CType(requestPropertyInfo.GetValue(request, Nothing), HttpWebRequest)
I think this is due to the "Nothing" being passed???

Does anyone know how to convert this? I've tried everything! The
parameter details are "index() As Object".

Any help would be much appreciated!!!

Jun 21 '06 #6
"GhostInAK" <gh*******@gmail.com> schrieb:
Your translation is wrong. You can't Dim uri As Uri.


'Dim uri As Uri' is actually allowed in VB.NET.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jun 21 '06 #7
Hello Herfried K. Wagner [MVP],

Seriously?? Then how the hell does VB figure out if you are talking about
the class or the variable?

-Boo
"GhostInAK" <gh*******@gmail.com> schrieb:
Your translation is wrong. You can't Dim uri As Uri.

'Dim uri As Uri' is actually allowed in VB.NET.

Jun 21 '06 #8
"GhostInAK" <gh*******@gmail.com> schrieb:
Seriously?? Then how the hell does VB figure out if you are talking about
the class or the variable?
Your translation is wrong. You can't Dim uri As Uri.

'Dim uri As Uri' is actually allowed in VB.NET.


Well, the class doesn't have instance members and the object doesn't have
shared members, so there is no ambiguity the compiler could not resolve.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 21 '06 #9
Hello Herfried K. Wagner [MVP],

Wow. That's so.. wrong. It makes me sad. I wanna cry.

Thanks Herfried.

-Boo
"GhostInAK" <gh*******@gmail.com> schrieb:
Seriously?? Then how the hell does VB figure out if you are talking
about the class or the variable?
Your translation is wrong. You can't Dim uri As Uri.

'Dim uri As Uri' is actually allowed in VB.NET.

Well, the class doesn't have instance members and the object doesn't
have shared members, so there is no ambiguity the compiler could not
resolve.

Jun 21 '06 #10

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

Similar topics

1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.