|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
c# to vb.net conversionI'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/2004/05/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(request, 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!!! "mcateer77" <bmcat***@gmail.com> schrieb: Your translation seems to be correct.> 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: -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Any idea why I'm getting this error?
Thks Herfried K. Wagner [MVP] wrote: Show quoteHide quote > "mcateer77" <bmcat***@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/> "mcateer77" <bmcat***@gmail.com> schrieb: Could you post the complete exception message?> Any idea why I'm getting this error? -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Here you go:
System.NullReferenceException: Object reference not set to an instance of an object. at DPS.dpsauthentication.dpsauthentication.GetWebRequest(Uri uri) in C:\Documents and Settings\brianmcateer.BRANDON\My Documents\Visual Studio Projects\DPS\dpsauthentication.vb:line 98 at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at DPS.dpsauthentication.dpsauthentication.DPSrequestToken(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! 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 Show quoteHide quote > 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/2004/05/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(request, 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!!! > "GhostInAK" <ghosti***@gmail.com> schrieb: 'Dim uri As Uri' is actually allowed in VB.NET.> Your translation is wrong. You can't Dim uri As Uri. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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 Show quoteHide quote > "GhostInAK" <ghosti***@gmail.com> schrieb: > >> Your translation is wrong. You can't Dim uri As Uri. >> > 'Dim uri As Uri' is actually allowed in VB.NET. > "GhostInAK" <ghosti***@gmail.com> schrieb: Well, the class doesn't have instance members and the object doesn't have > 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. 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/> Hello Herfried K. Wagner [MVP],
Wow. That's so.. wrong. It makes me sad. I wanna cry. Thanks Herfried. -Boo Show quoteHide quote > "GhostInAK" <ghosti***@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. > |
|||||||||||||||||||||||