01-13-2015 01:46 AM
Need help from NI to fix this CannotUnloadAppDomain exception.
It leads to a crash of the LabView IDE or any other calling instance.
Attached is a small VisualStudio project to build a ThreadRunner.dll and a VI referencing the dll. The crash happens 10 or more seconds after the VI execution finished.
Attach to the LabVIEW process to catch the exception in the Visual Studio debugger.
This is new to LabVIEW 2014!!! In LabVIEW 2013 the exception will be handled in the background.
System.CannotUnloadAppDomainException was unhandled
HResult=-2146234347
Message=Fehler beim Entladen der Anwendungsdomäne. (Ausnahme von HRESULT: 0x80131015)
Source=mscorlib
StackTrace:
bei System.AppDomain.Unload(AppDomain domain)
bei UnloadAppDomainInThreadProc(Object domain)
bei System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
bei System.Threading.ThreadPoolWorkQueue.Dispatch()
bei System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
01-13-2015 03:02 AM
Have you raised a service request with NI to report the issue? That's generally the best way to notify them and they should give you a CAR number for the issue so you can see when it get resolved.
01-13-2015 04:29 AM
...no response since 09/2014
Generally the best way is to make it public.
01-13-2015 05:25 AM
When I upgrade to LabVIEW 2014. I have many similar error messages. No matter in development mode or build into exe file. I feel sad.
01-13-2015 05:41 AM
When I start LabVIEW2014 I read
...We're Glad you asked!.... It's ok. Go ahead and expect more!
read this...Labview-2014-FPGA-memory-properties-change ...took me days to figure out...CAR closed without comment
01-13-2015 01:19 PM
@christian_w wrote:
Need help from NI to fix this CannotUnloadAppDomain exception.
It leads to a crash of the LabView IDE or any other calling instance.
Attached is a small VisualStudio project to build a ThreadRunner.dll and a VI referencing the dll. The crash happens 10 or more seconds after the VI execution finished.
Attach to the LabVIEW process to catch the exception in the Visual Studio debugger.
This is new to LabVIEW 2014!!! In LabVIEW 2013 the exception will be handled in the background.
System.CannotUnloadAppDomainException was unhandled
HResult=-2146234347
Message=Fehler beim Entladen der Anwendungsdomäne. (Ausnahme von HRESULT: 0x80131015)
Source=mscorlib
StackTrace:
bei System.AppDomain.Unload(AppDomain domain)
bei UnloadAppDomainInThreadProc(Object domain)
bei System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
bei System.Threading.ThreadPoolWorkQueue.Dispatch()
bei System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
I think the problem is in your error message there. When LabVIEW runs the VI you have, it is a top-level VI of a VI hierarchy. An AppDomain is created and executes your method (which starts a couple of threads by the looks of it). When your VI stops the VI hierarchy is now idle and as far as LabVIEW is concerned your application is finished. LabVIEW immediately unloads the AppDomain created to run your code. Unfortunately for you the .NET framework AppDomain.Unload() method requires that active threads in the AppDomain stop execution. If you are waiting on sockets then those worker threads are probably sitting in unmanaged code waiting on IO - they will not finish execution until they return or the host process is aborted. If you read the link below you'll see the unmanaged exception HRESULT is returned after a period of time attempting to unload the domain.
http://msdn.microsoft.com/en-us/library/system.appdomain.unload%28v=vs.110%29.aspx
As to why this did not occur in LabVIEW 2013 - I would check to see which CLR you are running under. Notice in the link I sent that the behaviour changed from CLR 2.0 -> CLR 4.0. Notice that it is possible for an AppDomain to not unload correctly and thus cause a memory leak. It is also possible that in LabVIEW 2014 this management was changed in order to expose this hidden issue. I would definitely contact NI and report this.
Regardless I would suggest that your code will not work as you intend it to. Welcome to the wonderful world of integration and multi-threading.
01-14-2015 02:11 AM
thanks for your reply
This code was only written to reproduce the error. There's no other use than to show the crash of LabVIEW and it's reported to NI.
From my point of view the exception has to be handled (like in LabVIEW2013) to prevent the crash of the calling instance.
In my case, my application calls functions from a LabVIEW interop assembly. Everything works fine until I close the reference. Seconds later we'll see the crash of the LabVIEW runtime.
09-14-2015 05:13 PM
Hi All,
I encountered the exact crash as you described for LabView 2014. Did you get a solution?
-yi
09-15-2015 02:27 AM
There's a AppDomain.CurrentDomain.DomainUnload event that should be handled by your code (DLL or .Net library).
You have to implement a Dispose() on DomainUnload to prevent the LabVIEW crash.
There was no input from NI to find a workaround and it's still a bug!
Hope it helps
Christian