Exception when using Outlook Securitymanager in C#

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

Exception when using Outlook Securitymanager in C#
 
Stefan P?tz




Posts: 3
Joined: 2022-07-19
Dear all,

we are using the Outlook Securitymanager in the newest Version in our C# project. So here is our code:


 public MailScanner()
        {
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            this.securityManager1 = new AddinExpress.Outlook.SecurityManager();
            oApp = null;
            OutlookApp = null;
            if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
            {
                oApp = Marshal.GetActiveObject("Outlook.Application") as Application;
            }
            else
            {
                oApp = new Application();
            }

            securityManager1.ConnectTo(oApp);
            securityManager1.DisableOOMWarnings = true;
...


The program runs in a loop and creates a new MailScanner object each time. So the program runs fine at first. But after a while we get an System.NullReferenceException when calling securityManager1.DisableOOMWarnings = true;

At the moment we do not do this after each loop:


finally {
manager.DisableOOMWarnings = false;
manager.Dispose();
}


Is it needed?

As this does only happen after a while we are bit stuck for finding the problem. Maybe someone can help out.
Posted 19 Jul, 2022 04:22:32 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Stefan,

Try to use 1) manager.DisableOOMWarnings = false and 2) securityManager1.Disconnect(oApp). I can't explain securityManager1 being null. Is this a one-thread application?

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 19 Jul, 2022 04:55:11 Top
Stefan P?tz




Posts: 3
Joined: 2022-07-19
Hello Andrej,

thanks for the very fast reply. We will try it. Yes it is a one threaded app.

Best regards,

Stefan
Posted 19 Jul, 2022 05:06:20 Top
Stefan P?tz




Posts: 3
Joined: 2022-07-19
Hello Andrej,

your hint regarding the threads pointed us to the right direction. We found some functionality in the application which was threaded. So sometimes our objects blew up. :-)

Thank you very much for your support. You can close this topic as resolved.
Posted 19 Jul, 2022 07:24:36 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Thank you, Stefan!

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 19 Jul, 2022 07:38:27 Top