(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:\InterfaceKey.snk")>
<Guid("1A3D56B8-9D12-1A34-1AF4-12AEF7654321"), _
InterfaceType(ComInterfaceType.InterfaceIsIDispatc h), _
DataSysDescription("The Shared Property Manager(SPM) announces its
Object URI address")> _
Public Interface ICentralSPM
<DispId(1), _
DataSysDescriptionAttribute("Sets the object URI address")> _
Function SetCentralPrimary(ByVal strObjectURI As String) As Boolean
<DispId(2), _
DataSysDescriptionAttribute("Gets the object URI address")> _
Function GetCentralPrimary(ByRef strObjectURI As String) As Boolean
End Interfac
-------------------------------INTERFACE----------------------------------------------
And my COM+ project looks like this :
-----------------------------COM+
Project---------------------------------------------
Imports System.EnterpriseServices
Imports System.Runtime.InteropServices
<Assembly: ApplicationAccessControl(True)>
<Assembly: AssemblyKeyFile("C:\COMPluskey.snk")>
<Assembly: ApplicationName("MyCOMPlus")>
<Assembly: ApplicationActivation(ActivationOption.Server)>
<Guid("1AB45AB8-12AB-12A4-1ABD-12AB87654321"), _
JustInTimeActivation(True), _
ComponentAccessControl(True), _
SecurityRole("Master"), _
SecurityRole("Guest", True)> _
Public Class clsSPM
Inherits ServicedComponent
Implements prjCentralSPM.ICentralSPM
Public Function SetCentralPrimary(ByVal strObjectURI As String) As
Boolean Implements prjCentralSPM.ICentralSPM.SetCentralPrimary
Dim oSPMManager As SharedPropertyGroupManager
Dim oSPMGroup As SharedPropertyGroup
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 SharedPropertyGroupManager
oSPMGroup = oSPMManager.CreatePropertyGroup("MySPM",
PropertyLockMode.SetGet, PropertyReleaseMode.Process, bExists)
' Does not matter if it exists or not
' Call to create will do check for me
oSPMProperty =
oSPMGroup.CreateProperty("CentralPrimaryAddress", bExists)
oSPMProperty.Value = strObjectURI
End If
Catch ex As Exception
'TODO: Error logging
Finally
oSPMProperty = Nothing
oSPMGroup = Nothing
oSPMManager = Nothing
End Try
End Function
Public Function GetCentralPrimary(ByRef strObjectURI As String) As
Boolean Implements prjCentralSPM.ICentralSPM.GetCentralPrimary
Dim oSPMManager As SharedPropertyGroupManager
Dim oSPMGroup As SharedPropertyGroup
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 SharedPropertyGroupManager
oSPMGroup = oSPMManager.CreatePropertyGroup("MySPM",
PropertyLockMode.SetGet, PropertyReleaseMode.Process, bExists)
If bExists = True Then
oSPMProperty =
oSPMGroup.CreateProperty("CentralPrimaryAddress", bExists)
strObjectURI = IIf(IsNumeric(oSPMProperty.Value), "",
oSPMProperty.Value)
If strObjectURI.Length > 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.Exception("Unauthorized 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\username") exists under Master->Users in Component Services
Dim bRetVal As Boolean = False
Try
If ContextUtil.IsSecurityEnabled Then
If SecurityCallContext.CurrentCall.IsCallerInRole("Ma ster")
= 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\username"
If ContextUtil.IsSecurityEnabled Then
Return SecurityCallContext.CurrentCall.OriginalCaller.Acc ountName
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.clsSPM
......
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'The following line gets an exception:
Me.m_comSPM = New MyCOMPLus.clsSPM
End Sub
....
-----------------Client--------------
I get the following Exception :
------------------Exception--------------
An unhandled exception of type 'System.IO.FileNotFoundException' 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.ICentralSPM"
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