COM+ Interface Error

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

    COM+ Interface Error

    (If Im posting in the wrong place concerning COM+ and .NET plz redirect me.)

    Hello all,

    Im writing a COM+ in VB.NET that is suppose to be able to set/get an
    address(String value).

    I've made a seperate project that contains all interfaces Im using in my
    entire project. But whenever I try to include the Interface in the COM+ class
    the initialization of the COM+ object fails. I get an exception.

    This is how the Interface looks
    -------------------------------INTERFACE----------------------------------------------
    <Assembly: AssemblyKeyFile ("C:\InterfaceK ey.snk")>

    <Guid("1A3D56 B8-9D12-1A34-1AF4-12AEF7654321"), _
    InterfaceType(C omInterfaceType .InterfaceIsIDi spatch), _
    DataSysDescript ion("The Shared Property Manager(SPM) announces its
    Object URI address")> _
    Public Interface ICentralSPM


    <DispId(1), _
    DataSysDescript ionAttribute("S ets the object URI address")> _
    Function SetCentralPrima ry(ByVal strObjectURI As String) As Boolean

    <DispId(2), _
    DataSysDescript ionAttribute("G ets the object URI address")> _
    Function GetCentralPrima ry(ByRef strObjectURI As String) As Boolean

    End Interfac
    -------------------------------INTERFACE----------------------------------------------

    And my COM+ project looks like this :
    -----------------------------COM+
    Project---------------------------------------------
    Imports System.Enterpri seServices
    Imports System.Runtime. InteropServices

    <Assembly: ApplicationAcce ssControl(True) >
    <Assembly: AssemblyKeyFile ("C:\COMPluskey .snk")>
    <Assembly: ApplicationName ("MyCOMPlus" )>
    <Assembly: ApplicationActi vation(Activati onOption.Server )>

    <Guid("1AB45A B8-12AB-12A4-1ABD-12AB87654321"), _
    JustInTimeActiv ation(True), _
    ComponentAccess Control(True), _
    SecurityRole("M aster"), _
    SecurityRole("G uest", True)> _
    Public Class clsSPM
    Inherits ServicedCompone nt
    Implements prjCentralSPM.I CentralSPM

    Public Function SetCentralPrima ry(ByVal strObjectURI As String) As
    Boolean Implements prjCentralSPM.I CentralSPM.SetC entralPrimary
    Dim oSPMManager As SharedPropertyG roupManager
    Dim oSPMGroup As SharedPropertyG roup
    Dim oSPMProperty As SharedProperty
    Dim bExists As Boolean
    Dim bRetVal As Boolean = False
    Dim bValidate As Boolean = True

    Try
    If Me.Validate Then
    oSPMManager = New SharedPropertyG roupManager
    oSPMGroup = oSPMManager.Cre atePropertyGrou p("MySPM",
    PropertyLockMod e.SetGet, PropertyRelease Mode.Process, bExists)
    ' Does not matter if it exists or not
    ' Call to create will do check for me
    oSPMProperty =
    oSPMGroup.Creat eProperty("Cent ralPrimaryAddre ss", bExists)
    oSPMProperty.Va lue = strObjectURI
    End If
    Catch ex As Exception
    'TODO: Error logging
    Finally
    oSPMProperty = Nothing
    oSPMGroup = Nothing
    oSPMManager = Nothing
    End Try

    End Function

    Public Function GetCentralPrima ry(ByRef strObjectURI As String) As
    Boolean Implements prjCentralSPM.I CentralSPM.GetC entralPrimary
    Dim oSPMManager As SharedPropertyG roupManager
    Dim oSPMGroup As SharedPropertyG roup
    Dim oSPMProperty As SharedProperty
    Dim bExists As Boolean
    Dim bRetVal As Boolean = False
    Dim bValidate As Boolean = True
    Try

    strObjectURI = ""

    If Me.Validate Then
    oSPMManager = New SharedPropertyG roupManager
    oSPMGroup = oSPMManager.Cre atePropertyGrou p("MySPM",
    PropertyLockMod e.SetGet, PropertyRelease Mode.Process, bExists)



    If bExists = True Then
    oSPMProperty =
    oSPMGroup.Creat eProperty("Cent ralPrimaryAddre ss", bExists)
    strObjectURI = IIf(IsNumeric(o SPMProperty.Val ue), "",
    oSPMProperty.Va lue)
    If strObjectURI.Le ngth > 0 Then
    bRetVal = True
    End If
    End If
    Else
    bValidate = False
    End If
    Catch ex As Exception
    'TODO: Error logging
    Finally
    oSPMProperty = Nothing
    oSPMGroup = Nothing
    oSPMManager = Nothing
    End Try
    'If bValidate is false means unauthorized person tried to get CPS
    Central .NET Object URI
    If bValidate = False Then
    Throw New System.Exceptio n("Unauthoriz ed User")
    End If

    Return bRetVal
    End Function


    Private Function Validate() As Boolean
    'Basically checks if the person who is calling has authority.
    'The IsCallerInRole returns true if the AccountName (ex:
    "domain\usernam e") exists under Master->Users in Component Services
    Dim bRetVal As Boolean = False
    Try
    If ContextUtil.IsS ecurityEnabled Then
    If SecurityCallCon text.CurrentCal l.IsCallerInRol e("Master")
    = True Then
    bRetVal = True
    End If
    End If
    Catch ex As Exception
    'TODO: Error logging
    End Try
    Return bRetVal
    End Function


    Public Function GetAccountName( ) As String
    'Basically return the account name ex "domain\usernam e"
    If ContextUtil.IsS ecurityEnabled Then
    Return SecurityCallCon text.CurrentCal l.OriginalCalle r.AccountName
    End If
    End Function

    End Class
    -----------------------------COM+
    Project---------------------------------------------

    After registering the COM+ application successfully using regsvcs I try
    creating the Object:
    -----------------Client--------------
    .....
    Private m_comSPM As MyCOMPLus.clsSP M
    ......
    Private Sub frmMain_Load(By Val sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    'The following line gets an exception:
    Me.m_comSPM = New MyCOMPLus.clsSP M
    End Sub
    ....
    -----------------Client--------------

    I get the following Exception :

    ------------------Exception--------------

    An unhandled exception of type 'System.IO.File NotFoundExcepti on' occurred
    in mscorlib.dll

    Additional information: File or assembly name prjCentralSPM, or one of
    its dependencies, was not found.
    ------------------Exception--------------

    If remove everything that has to do with the interface, i.e. implements
    those functions without using the line "Implements prjCentralSPM.I CentralSPM"
    it all works great.

    I've compared prjCentralSPM, MyCOMPlus and my Test project and they all have
    the same references added. So basically clueless why I cant include the
    Interface in the COM+. As a side note when I do include the interface I can
    see it in Component Services and it lists the two methods under
    Interfaces->ICentralSPM.

    Anybody know how to use Interfaces compiled in seperate projects in COM+?

    Best Wishes,
    Farek


Working...