We have .Net COM. It is developed in VB.Net. It's used in an application that stores mails from Outlook 2007 in MS SQL Server Database.
While using it in an application on WINDOWS Server 2008 R2 we get exception:
VB.NET:
Exception has been thrown [COLOR=#00008B]by[/COLOR] the target [COLOR=#00008B]of[/COLOR] an invocation. [COLOR=gray]-- at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)[/COLOR]
at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.__ComObject.CreateEventProvider(Type t)
at System.__ComObject.GetEventProvider(Type t)
at Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.add_Forward(ItemEvents_10_ForwardEventHandler )
at Emails7.cls_emlEmails.set_m_SelectedMail(MailItem WithEventsValue)
at Emails7.cls_emlEmails.
he code of SetSelectedMailM() function
VB.NET:
Private WithEvents m_InboxExplorer [COLOR=#00008B]As[/COLOR] Outlook.Explorer
Private WithEvents m_btnRegister [COLOR=#00008B]As[/COLOR] Microsoft.Office.Core.CommandBarButton
Private WithEvents m_SelectedMail [COLOR=#00008B]As[/COLOR] Outlook.MailItem
Private [COLOR=#00008B]Function[/COLOR] SetSelectedMailM() [COLOR=#00008B]As[/COLOR] Boolean
Dim bRes [COLOR=#00008B]As[/COLOR] Boolean = False
Try
[COLOR=#00008B]If[/COLOR] [COLOR=#00008B]Not[/COLOR] m_InboxExplorer [COLOR=#00008B]Is[/COLOR] Nothing AndAlso m_InboxExplorer.Selection.Count = [COLOR=#800000]1[/COLOR] AndAlso TypeOf (m_InboxExplorer.Selection.Item([COLOR=#800000]1[/COLOR])) [COLOR=#00008B]Is[/COLOR] Outlook.MailItem [COLOR=#00008B]Then[/COLOR]
m_SelectedMail = m_InboxExplorer.Selection.Item([COLOR=#800000]1[/COLOR])
m_btnRegister.Enabled = True
[COLOR=#00008B]Else[/COLOR]
m_SelectedMail = Nothing
[COLOR=#00008B]If[/COLOR] [COLOR=#00008B]Not[/COLOR] m_btnRegister [COLOR=#00008B]Is[/COLOR] Nothing [COLOR=#00008B]Then[/COLOR] m_btnRegister.Enabled = False
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]If[/COLOR]
bRes = True
Catch ex [COLOR=#00008B]As[/COLOR] Exception
Exceptions.PrintErrorToLog([COLOR=#800000]"SetSelectedMailM"[/COLOR], ex.Message & [COLOR=#800000]" --"[/COLOR] & ex.StackTrace)
[COLOR=#00008B]If[/COLOR] [COLOR=#00008B]Not[/COLOR] m_btnRegister [COLOR=#00008B]Is[/COLOR] Nothing [COLOR=#00008B]Then[/COLOR] m_btnRegister.Enabled = False
[COLOR=#00008B]Return[/COLOR] bRes
[COLOR=#00008B]End[/COLOR] Try
[COLOR=#00008B]Return[/COLOR] bRes
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]Function[/COLOR]
This code is working on Widows XP SP3 without any error.
Microsoft.Office.Interop.Outlook RuntimeVersion v1.1.4322.
The code is failing after more then 2 calls.
Last 2 actions in Outlook before calling SetSelectedMailM function are Delete Mail, Activate OutlookExplorer.
We got this problem after migrating to new remote terminal server.
Help me understand what is the problem, please.
Forward event handler is not exist in my code