avarghesein / ActiveX.NET

A true Out-Of-Proc (EXE) COM server implemented in C# Windows Application based on MEF Plugin Architecture. Develop COM objects in C# Libraries, which automatically get hosted in EXE COM Server, with minimal configuration.
MIT License
20 stars 9 forks source link

COM Client crashed if manually close Out-Of-Proc Server #6

Closed kafka-yu closed 5 years ago

kafka-yu commented 5 years ago

Hello avarghesein, Thanks for building this great tool.

I'm developing an IM provider(based COM) which will integrate to Outlook (COM Client) according to the guide: https://docs.microsoft.com/en-us/office/client-developer/shared/integrating-im-applications-with-office

Now everything is working. I use ActiveX as OutOfProc COM Server, after registers the Plugin(My IM provider), I make the COM server run forever by:

            if(cmdLine != null && cmdLine.Length > 0)
            {
                bool isRegister = false;
                //Condition Order is important
                if( cmdLine.Contains("/unregserver") || (isRegister = cmdLine.Contains("/regserver")))
                {                    
                    activeXContext.RegisterPlugins(!isRegister);
                    // return;*   <-------- Comment out
                }
            }

Now I can have interaction between the IM and Outlook contact card. Everything goes well.

Except:

  1. If I manually close the COM Server.
  2. Or I put PC to sleep state, then wake up again.

Above two scenarios will make the Outlook(COM Client? Since it will get COM instance from COM Server) crashed...

Do you know any kinds of reason that would make that happen? I cannot find any cause now ...

I can provide my IM app to you if needed.

Best regards, Ruakai

avarghesein commented 5 years ago

A few suggestions;

  1. Instead of (// return;* <-------- Comment out), you could rely on the first invocation to the ComServer, starts the process dynamically (than manually you do). To retain the process forever (you could comment out (ExitThread() call in Unlock() function in class ActiveXServerContext.cs)

  2. Do not forcefully close your ComServer, as it now retains many ComObjects used by consumer classes.

  3. In Outlook client, I presume you use VBA to connect to ComServer. Have some error handling there (may be using OnError GoTo Statements), and once you have a dangling ComServer Object, Reconstruct it again by calling CoCreateInstance(). This may not make the Outlook Crash, in case the server goes down.

avarghesein commented 5 years ago

Closing this issue, as confirmation is pending for quite long. Please do open a new issue, if you still having the issue, even after applying the above fix.