Jump to content

Share Property Function failed after conversion from vb6 to vb.net


Recommended Posts

After conversion SMP function fails on below highlighted code

VB6 Code:Public Function 
    If VBA.IsObject(strGrpName) = Fa

GetSPMProp(ByVal strGrpName As Variant, _
                            ByVal strPrpName As String, _
                            ByRef blnExists As Boolean) As Variant

    Dim spmGrp As COMSVCSLib.SharedPropertyGroup
    Dim spmPrp As COMSVCSLib.SharedProperty
    Dim blnGrpExists As Boolean
  ' get the SPM group

lse Then
        Set spmGrp = GetSPMGroup(LockSetGet, strGrpName, blnGrpExists)
    Else
        Set spmGrp = strGrpName
    End If

      
    ' create the SPM property
    Set spmPrp = spmGrp.CreateProperty(strPrpName, blnExists)

    ' get property value
    GetSPMProp = spmPrp.Value
    
    Set spmPrp = Nothing
    If VBA.IsObject(strGrpName) = False Then
        Set spmGrp = Nothing
    Else
        'Set spmGrp = strGrpName
    End If
    If GetSPMProp = "0" Then
        GetSPMProp = ""
    End If
    
    Set spmGrp = Nothing
    Set spmPrp = Nothing
    
End Function

VB.Net Code

Public Function GetSPMProp(ByVal strGrpName As Object, ByVal strPrpName As String, ByRef blnExists As Boolean) As Object

        Dim spmGrp As System.EnterpriseServices.SharedPropertyGroup
        Dim spmPrp As System.EnterpriseServices.SharedProperty

        Dim blnGrpExists As Boolean
        ' get the SPM group
        'UPGRADE_WARNING: IsObject has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
        If IsReference(strGrpName) = False Then
            'UPGRADE_WARNING: Couldn't resolve default property of object strGrpName. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            spmGrp = GetSPMGroup(COMSVCSLib.__MIDL___MIDL_itf_autosvcs_0001_0164_0001.LockSetGet, strGrpName, blnGrpExists)
        Else
            spmGrp = strGrpName-----this line throws error Unable to cast System.string to System.EnterpriseServices.SharedPropertyGroup
        End If


        ' create the SPM property
        spmPrp = spmGrp.CreateProperty(strPrpName, blnExists)

        ' get property value
        'UPGRADE_WARNING: Couldn't resolve default property of object GetSPMProp. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        GetSPMProp = spmPrp.Value

        'UPGRADE_NOTE: Object spmPrp may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
        spmPrp = Nothing
        'UPGRADE_WARNING: IsObject has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
        If IsReference(strGrpName) = False Then
            'UPGRADE_NOTE: Object spmGrp may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
            spmGrp = Nothing
        Else
            'Set spmGrp = strGrpName
        End If
        'UPGRADE_WARNING: Couldn't resolve default property of object GetSPMProp. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        If GetSPMProp = "0" Then
            'UPGRADE_WARNING: Couldn't resolve default property of object GetSPMProp. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            GetSPMProp = ""
        End If

        'UPGRADE_NOTE: Object spmGrp may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
        spmGrp = Nothing
        'UPGRADE_NOTE: Object spmPrp may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
        spmPrp = Nothing

    End Function

Link to post
Share on other sites
  • Mobilize.Net Staff

Hi,

This exception is related to late-binding in VB.NET. In this case strGrpName (defined as object in the method definition) is resolved as string in runtime.

There're a few options:

1. If strGrpName is always an string, then change its type from object to string in the parameter definition.
   This will imply  the offending line has to be modified as follows:
 spmGrp.Value = strGrpName

2. If there's not certainty on the real type for strGrpName: it could be strng, integer or any other datatype, then, the offending line could be modified as follows:
If (TypeOf strGrpName Is String) Then

   spmGrp.Value = Convert.ToString(strGrpName)

end if

Additional if-statements must be added for the other possible types of strGrpName.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use