Any help is much appreciated! I'm working on a minibroker application that will grap emails from a POP3 SSL server and build corresponding objects in SYS under a Home object called "MissedCalls." MissedCalls has a property called "Update" that is triggered so that Minibroker will run the subscribed .net subroutine. Everything works, except I always receive the error below when attempted to make the subscription.
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="Interop.MINIBROKERLib"
StackTrace:
at MINIBROKERLib.IRemotePremiseObject.SubscribeToProperty(String PropertyName, String NameOfCallbackFunction, Object ObjectContainingCallback)
at WindowsApplication1.Form1.Connect() in C:\Documents and Settings\etc6849\My Documents\Visual Studio 2005\Projects\PremiseClient\PremiseClient\Form1.vb:line 41
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\etc6849\My Documents\Visual Studio 2005\Projects\PremiseClient\PremiseClient\Form1.vb:line 22
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="Interop.MINIBROKERLib"
StackTrace:
at MINIBROKERLib.IRemotePremiseObject.SubscribeToProperty(String PropertyName, String NameOfCallbackFunction, Object ObjectContainingCallback)
at WindowsApplication1.Form1.Connect() in C:\Documents and Settings\etc6849\My Documents\Visual Studio 2005\Projects\PremiseClient\PremiseClient\Form1.vb:line 41
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\etc6849\My Documents\Visual Studio 2005\Projects\PremiseClient\PremiseClient\Form1.vb:line 22
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Code:
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports MINIBROKERLib
'OSPOP3_Plus is a free POP3 COM built for vb.net
Imports OSPOP3_Plus
Public Class Form1
Inherits System.Windows.Forms.Form
Private miniBroker As MINIBROKERLib.ISYSMiniBroker = New MINIBROKERLib.SYSMiniBroker()
Private oRoot As MINIBROKERLib.IRemotePremiseObject = Nothing
Private oHome As MINIBROKERLib.IRemotePremiseObject = Nothing
Private oMissedCalls As MINIBROKERLib.IRemotePremiseObject = Nothing
Private oCollectionMissedCalls As MINIBROKERLib.IRemotePremiseObjectCollection = Nothing
Private oMissedCall As MINIBROKERLib.IRemotePremiseObject = Nothing
Private oSession As New OSPOP3_Plus.Session
Private iSubscription As New Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Connect to Premise after user clicks the "Connect" button
Connect()
End Sub
Public Sub Connect()
' Connect to Premise
oRoot = miniBroker.Connect(Me.tbIPAddress.Text, Me.tbUserName.Text, Me.tbPassWord.Text)
oHome = oRoot.GetObject("sys://Home")
' Get MissedCalls object from SYS; if it doesn't exist, create it
Try
oMissedCalls = oRoot.GetObject("sys://Home/MissedCalls")
Catch oExc As Exception
oMissedCalls = oHome.CreateObject("sys://Schema/Modules/GoogleVoice/Classes/MissedCalls", "MissedCalls")
End Try
GetMissedCalls(oMissedCalls)
' Subscribe to Home.MissedCalls.Update
' Update is a boolean property that a timer will toggle periodically within SYS
' This should then run the UpdateCallBack() subroutine found below
oMissedCalls.SubscribeToProperty("Update", "UpdateCallBack", Me)
End Sub
'ByVal subscriptionID As Long, ByVal parent As MINIBROKERLib.IRemotePremiseObject, ByVal obj As MINIBROKERLib.IRemotePremiseObjectByVal subscriptionID As Long, ByVal parent As MINIBROKERLib.IRemotePremiseObject, ByVal obj As MINIBROKERLib.IRemotePremiseObject
Public Sub UpdateCallBack()
'Dim line As String
' Initialize POP3
oSession = New OSPOP3_Plus.Session
With oSession
.RaiseError = False
.Timeout = oMissedCalls.GetValue("Timeout")
.ServerName = oMissedCalls.GetValue("POP3Server")
.Login = oMissedCalls.GetValue("AccountName")
.Password = oMissedCalls.GetValue("AccountPassword")
.PortNumber = oMissedCalls.GetValue("PortNumber")
.UseSSL = oMissedCalls.GetValue("UseSSL")
End With
oMissedCalls.SetValue("Status", "Connecting...")
ClearMissedCalls()
GetMissedCalls(oMissedCalls)
'line = String.Format("Property id {1} of ojbect {1} has changed.", obj.ObjectID, Parent.Name)
'MsgBox(line)
End Sub
Sub ClearMissedCalls()
oCollectionMissedCalls = oMissedCalls.GetObjectsByType("sys://Schema/Modules/GoogleVoice/Classes/MissedCall", False)
For Each oMissedCall In oCollectionMissedCalls
If Not IsNothing(oMissedCall) Then
oMissedCalls.DeleteObject(oMissedCall.Name)
'oHome.DeleteObject("MissedCall1")
End If
Next
End Sub
Sub GetMissedCalls(ByVal oMissedCalls As MINIBROKERLib.IRemotePremiseObject)
Dim oMLE As OSPOP3_Plus.MessageListEntry
Dim oMessage As OSPOP3_Plus.Message
Dim iNum As Integer
Dim iMsgCount As Integer
Dim oStoreMissedCall As MINIBROKERLib.IRemotePremiseObject
If oSession.OpenPOP3 Then
oMissedCalls.SetValue("Status", "Acquiring MissedCalls information ...")
oSession.GetMailboxSize()
oMissedCalls.SetValue("MissedCallCount", 0)
iMsgCount = oSession.GetMessageCount()
oSession.GetMessageList()
For Each oMLE In oSession.MessageList
If 200 > oMLE.ID > (oSession.GetMessageCount() - oMissedCalls.GetValue("MaxMissedCalls")) Then
oMessage = oSession.GetMessage(oMLE.ID)
If oMessage.Sender.Address = "[email protected]" Then
iNum = iNum + 1
oMissedCalls.SetValue("MissedCallCount", oMissedCalls.GetValue("MissedCallCount") + 1)
If iNum <= oMissedCalls.GetValue("MaxMissedCalls") Then
oStoreMissedCall = oMissedCalls.CreateObject("sys://Schema/Modules/GoogleVoice/Classes/MissedCall", "MissedCall" & iNum)
oMessage = oSession.GetMessage(oMLE.ID)
oStoreMissedCall.SetValue("EMID", oMLE.ID)
oStoreMissedCall.SetValue("SenderName", oMessage.Sender.Name)
oStoreMissedCall.SetValue("SenderAddress", oMessage.Sender.Address)
oStoreMissedCall.SetValue("CallDetails", oMessage.Subject)
'.DateCallReceived = this.ConvertDate(oMissedCall.DateSent)
'.CallDetails = Trim(Left(oMissedCall.Subject, Len(oMissedCall.Subject) - 11))
Else
Exit For
End If
End If
End If
Next
oMessage = Nothing
oMLE = Nothing
oSession.ClosePOP3()
oMissedCalls.SetValue("DisplayName", oMissedCalls.GetValue("Name") & ": " & oMissedCalls.GetValue("MissedCallCount"))
oMissedCalls.SetValue("LastUpdate", Now)
oMissedCalls.SetValue("Status", "Idle")
Else
oMissedCalls.SetValue("Status", "Unable to open MissedCalls.")
End If
' Let SYS handle the update timer instead...?
' Reset the MissedCalls polling timer
'If oMissedCalls.GetValue("UpdateInterval") > 0 Then
'System.addTimer(this.UpdateInterval * 60, "this.Update=true", 1, this.name & this.ObjectID)
'End If
End Sub
End Class