c# to vb.net conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mcateer77

    #1

    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.Reflecti on;

    protected override System.Net.WebR equest GetWebRequest(U ri uri)
    {
    PropertyInfo requestProperty Info = null;
    WebRequest request = base.GetWebRequ est(uri);
    if (requestPropert yInfo==null)
    requestProperty Info = request.GetType ().GetProperty( "Request");
    // Retrieve underlying web request
    HttpWebRequest webRequest =
    (HttpWebRequest )requestPropert yInfo.GetValue( request, null);
    webRequest.Keep Alive = false;
    return request;
    }


    I've done this so far:

    Imports System.Net
    Imports System.Reflecti on

    Protected Overloads Overrides Function GetWebRequest(B yVal uri As Uri)
    As System.Net.WebR equest
    Dim requestProperty Info As PropertyInfo = Nothing
    Dim request As WebRequest = MyBase.GetWebRe quest(uri)
    If requestProperty Info Is Nothing Then
    requestProperty Info =
    request.GetType .GetProperty("R equest")
    End If
    Dim webRequest As HttpWebRequest =
    CType(requestPr opertyInfo.GetV alue(request, Nothing), HttpWebRequest)
    webRequest.Keep Alive = False
    Return request
    End Function

    When I run this i get the following error:

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

    This occurs on the following line:

    Dim webRequest As HttpWebRequest =
    CType(requestPr opertyInfo.GetV alue(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!!!

  • Herfried K. Wagner [MVP]

    #2
    Re: c# to vb.net conversion

    "mcateer77" <bmcateer@gmail .com> schrieb:[color=blue]
    > 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:[/color]

    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/>

    Comment

    • mcateer77

      #3
      Re: c# to vb.net conversion

      Any idea why I'm getting this error?

      Thks

      Herfried K. Wagner [MVP] wrote:[color=blue]
      > "mcateer77" <bmcateer@gmail .com> schrieb:[color=green]
      > > 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:[/color]
      >
      > 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/>[/color]

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: c# to vb.net conversion

        "mcateer77" <bmcateer@gmail .com> schrieb:[color=blue]
        > Any idea why I'm getting this error?[/color]

        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/>

        Comment

        • mcateer77

          #5
          Re: c# to vb.net conversion

          Here you go:

          System.NullRefe renceException: Object reference not set to an instance
          of an object.
          at DPS.dpsauthenti cation.dpsauthe ntication.GetWe bRequest(Uri uri) in
          C:\Documents and Settings\brianm cateer.BRANDON\ My Documents\Visua l
          Studio Projects\DPS\dp sauthentication .vb:line 98
          at
          System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
          methodName, Object[] parameters)
          at DPS.dpsauthenti cation.dpsauthe ntication.DPSre questToken(Int3 2
          version, String vendorID) in C:\Documents and
          Settings\brianm cateer.BRANDON\ My Documents\Visua l Studio
          Projects\DPS\dp sauthentication .vb:line 49
          at DPS.Form1.Butto n1_Click(Object sender, EventArgs e) in
          C:\Documents and Settings\brianm cateer.BRANDON\ My Documents\Visua l
          Studio Projects\DPS\Fo rm1.vb:line 94

          Thanks!

          Comment

          • GhostInAK

            #6
            Re: c# to vb.net conversion

            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.Reflecti on



            Protected Overrides Function GetWebRequest(B yVal tURI As Uri) As System.Net.WebR equest

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

            If Nothing Is tPropertyInfo Then
            tPropertyInfo = tRequest.GetTyp e.GetProperty(" Request")
            End If
            tRequestToo = tPropertyInfo.G etValue(tReques t, Nothing)
            tRequestToo.Kee pAlive = False

            Return tRequest

            End Function

            -Boo
            [color=blue]
            > 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.Reflecti on;
            > protected override System.Net.WebR equest GetWebRequest(U ri uri)
            > {
            > PropertyInfo requestProperty Info = null;
            > WebRequest request = base.GetWebRequ est(uri);
            > if (requestPropert yInfo==null)
            > requestProperty Info = request.GetType ().GetProperty( "Request");
            > // Retrieve underlying web request
            > HttpWebRequest webRequest =
            > (HttpWebRequest )requestPropert yInfo.GetValue( request, null);
            > webRequest.Keep Alive = false;
            > return request;
            > }
            > I've done this so far:
            >
            > Imports System.Net
            > Imports System.Reflecti on
            > Protected Overloads Overrides Function GetWebRequest(B yVal uri As Uri)
            > As System.Net.WebR equest
            > Dim requestProperty Info As PropertyInfo = Nothing
            > Dim request As WebRequest = MyBase.GetWebRe quest(uri)
            > If requestProperty Info Is Nothing Then
            > requestProperty Info =
            > request.GetType .GetProperty("R equest")
            > End If
            > Dim webRequest As HttpWebRequest =
            > CType(requestPr opertyInfo.GetV alue(request, Nothing), HttpWebRequest)
            > webRequest.Keep Alive = False
            > Return request
            > End Function
            > When I run this i get the following error:
            >
            > "System.NullRef erenceException : Object reference not set to an
            > instance of an object."
            >
            > This occurs on the following line:
            >
            > Dim webRequest As HttpWebRequest =
            > CType(requestPr opertyInfo.GetV alue(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!!!
            >[/color]


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: c# to vb.net conversion

              "GhostInAK" <ghostinak@gmai l.com> schrieb:[color=blue]
              > Your translation is wrong. You can't Dim uri As Uri.[/color]

              '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/>

              Comment

              • GhostInAK

                #8
                Re: c# to vb.net conversion

                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
                [color=blue]
                > "GhostInAK" <ghostinak@gmai l.com> schrieb:
                >[color=green]
                >> Your translation is wrong. You can't Dim uri As Uri.
                >>[/color]
                > 'Dim uri As Uri' is actually allowed in VB.NET.
                >[/color]


                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: c# to vb.net conversion

                  "GhostInAK" <ghostinak@gmai l.com> schrieb:[color=blue]
                  > Seriously?? Then how the hell does VB figure out if you are talking about
                  > the class or the variable?
                  >[color=green][color=darkred]
                  >>> Your translation is wrong. You can't Dim uri As Uri.
                  >>>[/color]
                  >> 'Dim uri As Uri' is actually allowed in VB.NET.[/color][/color]

                  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/>

                  Comment

                  • GhostInAK

                    #10
                    Re: c# to vb.net conversion

                    Hello Herfried K. Wagner [MVP],

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

                    Thanks Herfried.

                    -Boo
                    [color=blue]
                    > "GhostInAK" <ghostinak@gmai l.com> schrieb:
                    >[color=green]
                    >> Seriously?? Then how the hell does VB figure out if you are talking
                    >> about the class or the variable?
                    >>[color=darkred]
                    >>>> Your translation is wrong. You can't Dim uri As Uri.
                    >>>>
                    >>> 'Dim uri As Uri' is actually allowed in VB.NET.
                    >>>[/color][/color]
                    > 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.
                    >[/color]


                    Comment

                    Working...