Value does not fall within expected range

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

Value does not fall within expected range
in standalone C# 2010 app with Outlook interop 
Ken Kaufman




Posts: 4
Joined: 2011-02-09
application = new Microsoft.Office.Interop.Outlook.Application();
securityManager = new SecurityManager();
securityManager.ConnectTo(application);

...generates "Value does not fall within expected range" exception.

Application is compiled as x86 (32 bit) with Outlook 2007 also running as 32 bit.

I went through all the documentation and this entire forum, can't figure out what I'm doing wrong. I'd rather use the Outlook interop than do the direct COM calls like in the sample code.

If I omit the ConnectTo entirely I still get the Outlook popups.

Any help would be appreciated.
Posted 09 Feb, 2011 10:30:49 Top
Renat Tlebaldziyeu


Guest


Hello Ken,

Do you use this code in the main or a background thread of your application?
Posted 09 Feb, 2011 11:03:13 Top
Ken Kaufman




Posts: 4
Joined: 2011-02-09
Hi,

The code sample shown above executes on the main thread.

I have the application set up on a timer to check emails periodically. So later on, the routine that actually checks the mail items executes on a timer callback on a separate thread.

Thanks.
Posted 09 Feb, 2011 11:11:11 Top
Renat Tlebaldziyeu


Guest


Ken,

Does your application work as the MTA or STA thread?
What kind of timer do you use? Is it System.Timers.Timer or System.Windows.Forms.Timer?

Please try to move secman.dll from the "[Common files]\Outlook security manager\" folder to another location and register it manually from the command line:
regsvr32 "path to secman.dll"
Does your application work without exception after secman.dll is moved?
Posted 09 Feb, 2011 11:31:40 Top
Ken Kaufman




Posts: 4
Joined: 2011-02-09
I've structured it as a c# console app...

1) MTA Thread
2) System.Threading.Timer
3) No. I just moved secman.dll to c:\Windows\SysWOW64 and registered it. The registration succeeded but I still get the same exception from .NET.
Posted 09 Feb, 2011 11:47:36 Top
Renat Tlebaldziyeu


Guest


Hello Ken,

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 10 Feb, 2011 03:09:54 Top
Ken Kaufman




Posts: 4
Joined: 2011-02-09
I restructured from a console app to a windows form based app with [STAThread] attribute and it seems to be working now. I suspect you shouldn't run in free threaded mode when working with COM, although the rest of my program seems to be able to access emails without incident.

If you want to replicate the issue, create a windows console app in C#. If the [STAThread] attribute is not present (above the Main() entry point), my code snippet above generates the exception. If I add back the [STAThread] attribute, no exception is generated.

If its behaving differently on your side, let me know & I'll put together a small sample project.
Posted 10 Feb, 2011 09:40:29 Top
Renat Tlebaldziyeu


Guest


Hello Ken,

I have reproduced the issue on my PC. It is filed under #2349 in our bug-tracking system and will be fixed in the next public build of the .NET edition of Outlook Security Manager. Thank you for pointing this out to me.

As a workaround, please try the following steps:

1. Delete secman.dll and secman64.dll from the "[Common files]\Outlook security manager\" folder;
2. Delete secman.dll and secman64.dll from your application folder;
3. Put secman.dll and secman64.dll to some other folder (you can find the dlls in the Outlook Security Manager Redistributable folder);
4. Register secman.dll or secman64.dll depending on the bitness of the installed Outlook version.

Or use the [STAThread] attribute for your main function.
Posted 10 Feb, 2011 10:24:20 Top