dotnet interop:
I am getting "An event was unable to invoke any of the subscribers (Exception
from HRESULT: 0x80040201)" on what appears to have been a properly subscribed
transient event.
I have an Event Class in a signed library, LceEvent.dll, registered in COM+
via
regsvcs LceEvent.dll
--------------------------------------------------------------------------------
Imports System.Runtime.InteropServices
Imports System.EnterpriseServices
<ComVisible(True)> _
Public Interface ITheEvent
Sub Fire()
End Interface
<ComVisible(True), _
EventClass()> _
Public Class TheEvent
Inherits ServicedComponent
Implements ITheEvent
Public Sub Fire() Implements ITheEvent.Fire
End Sub
End Class
--------------------------------------------------------------------------------
above class registers appropriately
I have a sink library, LceSink.dll with an Event Sink :
--------------------------------------------------------------------------------
Imports System.EnterpriseServices
Imports System.Runtime.InteropServices
Imports LceEvent
<ComVisible(True)> _
Public Class TheEventSink
Implements ITheEvent
Public Event Fired As EventHandler
Private _subId As String
Public Sub New()
End Sub
Public Sub Fire() Implements LceEvent.ITheEvent.Fire
RaiseEvent Fired(Me, EventArgs.Empty)
End Sub
End Class
--------------------------------------------------------------------------------
I have a helper class for transient subscriptions:
--------------------------------------------------------------------------------
Public Class LceHelper
Public Shared Function CreateTransientSubscription( _
ByVal clsid As String, ByVal subscriber As Object) As String
Dim catalog As New COMAdmin.COMAdminCatalog
Dim catalogCollection As COMAdmin.COMAdminCatalogCollection = _
catalog.GetCollection("TransientSubscriptions")
catalogCollection.Populate()
Dim subscription As COMAdmin.ICatalogObject = catalogCollection.Add()
subscription.Value("SubscriberInterface") = subscription
subscription.Value("EventCLSID") = "{" & clsid & "}"
subscription.Value("Name") = "TransientSubscription"
catalogCollection.SaveChanges()
' POINT 1
Return subscription.Value("ID").ToString()
End Function
Public Shared Sub DeleteTransientSubscription(ByVal subid As String)
Dim catalog As New COMAdmin.COMAdminCatalog
Dim catalogCollection As COMAdmin.COMAdminCatalogCollection = _
catalog.GetCollection("TransientSubscriptions")
catalogCollection.Populate()
' POINT 5
For i As Integer = 0 To catalogCollection.Count - 1
Dim subscription As COMAdmin.COMAdminCatalogObject =
catalogCollection.Item( i )
If subscription.Value("ID").ToString() = subid Then
catalogCollection.Remove( i )
Return
End If
Next
End Sub
End Class
--------------------------------------------------------------------------------
I am trying to use in a form:
--------------------------------------------------------------------------------
Public Class Form1
Private WithEvents _TheSink As LceSink.TheEventSink
Private _thesub As String
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim t As Type
t = Type.GetTypeFromProgID("LceEvent.TheEvent")
_TheSink = New LceSink.TheEventSink()
Try
_thesub = LceSink.LceHelper.CreateTransientSubscription( _
t.GUID.ToString(),
_TheSink)
' POINT 2
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
MyBase.OnLoad(e)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim evt As LceEvent.ITheEvent = New LceEvent.TheEvent
Try
' POINT 3
evt.Fire()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Disposed
' POINT 4
LceSink.LceHelper.DeleteTransientSubscription(_thesub)
End Sub
End Class
--------------------------------------------------------------------------------
At POINT 1 (LceHelper.CreateTransientSubscription), catalogCollection.Count
has increased by 1
At POINT 2 (Form1 above), it appears the subscription succeeds as the call
to CreateTransientSubscription assigns a giud string to _subID
At POINT 3 (Form1 above), I get exception An event was unable to invoke any
of the subscribers (Exception from HRESULT: 0x80040201)
At POINT 4 (Form1 above), trace into LceHelper.DeleteTransientSubscription
At POINT 5 (LceHelper.DeleteTransientSubscription )CatalogCollection.Count >
1, the subid is found and the subscription is released
What am i doing wrong? Why isnt the subscription being called?