PISDK and EventPipe usage in AppDomains

Discussion created by UlrichSchneider on Oct 4, 2011
Latest reply on Oct 17, 2011 by UlrichSchneider



I have a strange problem regarding the PI-SDK and EventPipes in several AppDomains. The host application is opens for each application purpose a new AppDomain and loads assemblies into memory to run code. Some of the loaded assemblies referes to the PI-SDK. It is possible to shut down the hosted applications and start it up again (in fact unloading and loading AppDomains). This works good as long as EventPipes of the PI-SDK are not used.


Everytime when an AppDomain gets destroyed which used PI-SDK EventPipes (more properly: The last AppDomain which used PI-SDK EventPipes) I am no longer able to instantiate any new AppDomain (PISDK) and use it. New and existing instances of PI-SDK will throw error messages like:
- COM object that has been separated from its underlying RCW cannot be used.
- External component has thrown an exception.
- Unable to open a session on a server. [0] Success     (<-- my personal favourite)
- Unable to cast COM object of type 'PISDK.PISDKClass' to interface type 'PISDK.IPIAppIdentity'. The operation failed because the QueryInterface call on the COM component for the interface with IID '{...
- Time out on a SDK lockSDKSessionMgr lock.


I need to destroy the host-application and restart it to get the things working again.


I have read in the SDK documentation that a special thread ist started once an EventPipe is used. This thread is called "Event Retrieval Thread" in the documentation. I am releasing the objects regarding EventPipe and PISDK properly before I am unloading an AppDomain (e.g. remove signals from eventpipe, unregister from the NewValue-event, destroy eventpipe object, destroy the PointList object, finally destroy PISDK-object). But anyway it seems there is something not released properly.


Collectively, using PISDK in several AppDomains is not a problem until EventPipes are used. If the last AppDomain holding a reference to a PI-SDK using EventPipes is destroyed I can no longer use any PI-SDK functionality.


I am asking now for some assistance regarding "How to clean up PI-SDK properly"? Maybe somebody has already worked with PI-SDK and Application Domains and has some experience to share with me?


I appreciate any help.