Continuation of previously reported issue

Add-in Express™ Support Service
That's what is more important than anything else

Continuation of previously reported issue
Previous post is located here: http://www.add-in-express.com/forum/read.php?FID=11&TID=10446 
Mykhaylo Khodorev


Guest


I have got information about same issue as reported in previous (http://www.add-in-express.com/forum/read.php?FID=11&TID=10446) post:

System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
at AddinExpress.Outlook.IOutlookSecurityManager2.Check(Int32 apiType)
at AddinExpress.Outlook.SecurityManager.set_DisableOOMWarnings(Boolean value)
...

The version of Security Manager library is 3.0.3.2
Posted 29 Mar, 2012 15:18:13 Top
Andreas May




Posts: 10
Joined: 2008-09-02
Hi all,

I have the same problem with this version.
I am trying to create a sample program that reproduces the error.
But maybe there's something new that could help one?

Otherwise, it just seems like the threads cause problems more recently. Previously it was possible to use threads. Now thread cause this exact problem.

Although I have removed all of the threads in my application. There is only a single call which is controlled via System.Windows.Forms.Timer. However, there is also a problem if I disable it.
Posted 30 Mar, 2012 01:05:30 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Mikhaylo and Andreas,

Pay attention that calling an Office object model in a background thread is NOT recommended.

Internally, Security Manager makes a call to the Outlook object model to get the active explorer. Such a call may fail because the host application may not be in a state to handle the call and can reject it. This is often the case with using object models in a thread. But "visible" exceptions is only one part of the problem.

The other part is problems that you user may find later. In http://www.add-in-express.com/creating-addins-blog/2010/11/04/threads-managed-office-extensions/ I described problems reproted to us by end users when our code checked Inspectors.Count in the background.

You can send us a sample project demonstrating the exception: please find the support email address in {Add-in Express installation folder}\readme.txt; make sure your email contains a link to this topic. I also ask you to test your sample project with the Security Manager code commented out completely.

Note that using System.Windows.Forms.Timer is a suggested approach to bypass the problems. Make sure the timer is run on the main thread.


Andrei Smolin
Add-in Express Team Leader
Posted 30 Mar, 2012 05:53:25 Top
Mykhaylo Khodorev


Guest


How Timer can help avoid the problem?

Your colleague Renat already has copy of my project, which has mentioned problem. Difficult thing is that this issue doesn't occur always so I can't tell exact steps to reproduce it.
Posted 02 Apr, 2012 11:31:09 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hi Mykhaylo,

You need to use the Outlook obhject model in just one thread. For an add-in this thread is Outlook's main foreground thread. For a standalone application (this is your case) you need to create, use and release the Outlook object model (OOM) in any given thread; using OOM outside of this thread is a mistake that can produce the behavior that you see.

In your code, SettingsForm.Sync() creates a thread; then Syncronizer assigns this._outlookApp to Properties.Settings.Default.OutlookApplication. I suppose that this assignment is the source of your problems; I suppose this is the place where the reference to an OOM's object is passed to another thread.

In your code, I see a class that uses this declaration on the class level:

protected Outlook.NameSpace _outlookConnection;

I suppose this class uses the Outlook object model on a thread other than the one created in SettingsForm.Sync(). BTW, I wonder if your code can create two Syncronizers. I also wonder if Outlook.exe is left hanging in the Processes list of the Task Manager window after your app quits.

My reference to System.Windows.Forms.Timer is a way to bypass calling the Outlook object model in another thread. The fact is that the Tick event of the System.Windows.Forms.Timer class occurs on the same thread where the timer is created - usually, this is the application's main foreground thread.


Andrei Smolin
Add-in Express Team Leader
Posted 03 Apr, 2012 04:37:15 Top
Andreas May




Posts: 10
Joined: 2008-09-02
Hello Mr. Smolin,

at the following link you will find a sample project.

http://www.cobrasystem.de/cobra/download/dev/OutlookSample.zip

The project has been written down relatively quickly, but I hope it helps anyway.
Posted 03 Apr, 2012 05:23:46 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Andreas,

My name is Andrei :)

I've just run your project without any problems on my Outlook 2010 32-bit SP1 (14.0.6112.5000). What Outlook version are you usinh? Have you turned all other COM add-ins off?


Andrei Smolin
Add-in Express Team Leader
Posted 03 Apr, 2012 07:48:16 Top
Andreas May




Posts: 10
Joined: 2008-09-02
Hi Andrei,

I was worried that the error will not occur;-)

I use Outlook 2010 as 32-bit SP1 (14.0.6112.5000) and have disabled all add-ons.

Unfortunately, the problem does not in any computer, sometimes it works without problems several times and then eventually appeared on the error.

I wish it had more information.
Posted 03 Apr, 2012 09:25:47 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hi Andreas,

I suggest checking if the issue is reproducible after you turn the antivirus off.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Apr, 2012 04:11:04 Top