COM Timeout using P/Invoke

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

COM Timeout using P/Invoke
 
Trevor Watson




Posts: 3
Joined: 2011-05-20
We were attempting to use your Outlook Security Manager to disable the warning box when calling SaveAs (via P/Invoke) in all versions of Outlook. The code is in a plug-in that is called by another program, but all tasks run in the plugin in the same thread.

I found that running it against one PST was not an issue (we create a new instance of outlook, do our processes and then call Quit on the outlook application).

I call outlookSecManager.ConnectTo(oApp) after creating the outlook application and at the end call outlookSecManager.Disconnect(oApp). When we process more than one PST file though (after we've called Quit and discarded all objects (entirely new call to the function)) the ConnectTo locks up.

I thought that it might be that I didn't call Dispose on the SecurityManager object so I added a line outlookSecManager.Dispose(). However (there's always a however isn't there?), the Dispose line appears to time out with the error

"The CLR has been unable to transition from COM context 0x1a2680 to COM context 0x1a28a8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages."

Taking the .Dispose line out (since it's doing something disastrous) results in the process running through fine once, but the 2nd time i try to call "ConnectTo" it takes a long time and gives back the same error.

Our version is
SecurityManager.2005.dll - 6.1.3017.2005
secman.dll - 3.0.3.0

Visual Studio 2005
Outlook 2003

Any assistance would be greatly appreciated as I've just been notified that the release date for this project has been moved up to this Tuesday >.<

Thanks

Trevor Watson
Posted 20 May, 2011 16:40:35 Top
Renat Tlebaldziyeu


Add-in Express team


Posts: 132
Joined: 2010-02-15
Hi Trevor,

Could you please send me a sample project, which reproduces the issue (please see readme.txt for the support e-mail address and make sure your e-mail contains a link to this topic)?
Posted 21 May, 2011 04:59:57 Top
Renat Tlebaldziyeu


Add-in Express team


Posts: 132
Joined: 2010-02-15
Trevor, do you get this error when you are debugging your application?
If it's so, please try the following steps:
1. go to the Visual Studio Debug menu -> Exceptions...
2. in the Managed Debug Assistants section, uncheck the ContextSwitchDeadlock.
Did it help?
Posted 21 May, 2011 09:21:36 Top
Trevor Watson




Posts: 3
Joined: 2011-05-20
Disabling the ContextSwitchDeadlock error gives me a new error that reads

"An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss."

This occurs on the second pass.

I'm going to send you some code to your email address shortly.
Posted 23 May, 2011 10:45:52 Top
Renat Tlebaldziyeu


Add-in Express team


Posts: 132
Joined: 2010-02-15
Thank you for providing me with the sample code, Trevor.
I'm sorry, I wasn't able to debug your code. Could you please create a small project which reproduces the issue?

Please note that you don't need to set the DisableCDOWarnings and DisableSMAPIWarnings properties to True.
Please remove the following lines from your code:
...
outlookSecManager.DisableCDOWarnings = true;
outlookSecManager.DisableSMAPIWarnings = true;
...
outlookSecManager.DisableCDOWarnings = false;
outlookSecManager.DisableSMAPIWarnings = false;
...

"An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss."

Do you get this error if your program works in release mode?
Posted 23 May, 2011 11:46:16 Top
Trevor Watson




Posts: 3
Joined: 2011-05-20
Running in release mode does not give this error. Instead it gets to the ConnectTo line of code and locks up solid. No exception or anything.
Posted 23 May, 2011 12:52:08 Top
Renat Tlebaldziyeu


Add-in Express team


Posts: 132
Joined: 2010-02-15
Trevor, could you please prepare and send me a small sample project which reproduces the issue?
Posted 24 May, 2011 02:37:29 Top
Renat Tlebaldziyeu


Add-in Express team


Posts: 132
Joined: 2010-02-15
It seems I found the cause of the issue. I've sent you the new test build with the fix. Please test your application with the new build and let me know about the results.
Posted 24 May, 2011 05:37:37 Top