Browser control in separate AppDomain crash on exit

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have a form with a browser control (AxInterop.ShDocVw.AxWebBrowser). The
form is opened in a separate AppDomain. I find that when I close down my app
(unmanaged app calling via interop into assembly which creates separate
AppDomain and shows form), I get an exception thrown or crash generated
(release or debug build respectively), the exception being a
NullReferenceException thrown from AxHost.ConnectionPointCookie.Disconnect.
If I manually Dispose the AxHost object after I have closed the form, then
the problem vanishes.

The AxHost.ConnectionPointCookie.Disconnect is being called via
AxHost.Finalize, presumably via garbage collection when the AppDomain is
unloaded. The difference I notice between 'normal' and 'manual Dispose'
scenarios is that System.__ComObject.m_wrap is null and non-null
respectively in the two cases.

It appears as though the AppDomain unload is blowing away the COM object
before calling garbage collection so that the Marshal.ReleaseComObject in
ConnectionPointCookie.Disconnect barfs. I understand that unloading an
AppDomain releases COM objects loaded into that AppDomain, but should it be
working at cross-purposes like this? Is this a .NET bug?


.



Relevant Pages

  • Re: keeping asp.net pages warm
    ... You can keep the AppDomain loaded in the same manner as you suggest, but the tendancy is to unload the AppDomain if it's not being used; you may have other apps running on the server that might like those resources. ... The behavior of shutting down the Application if it's not being used is more common in Windows 2003 where if the app is idle for 20 minutes it's shutdown. ... windows service or scheduled task that requests for asp.net page from ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Question on article by Scott about "Shadow copy of an assembly
    ... Base's bin directory as I am building the project on server. ... Why would it reload the AppDomain if IIS shadow copied my old assembly? ... you still need to compile the assemblies in the IDE. ... I just finished reading an interesting article by Scott about App Domains: ...
    (microsoft.public.dotnet.framework.aspnet)
  • appdomain.unload
    ... appdomain.unload call fails and no exception is caught. ... some problem with non-managed resources locking my appdomain as this ... app is a dumping ground and calls into all kinds of stuff; ... there are some posts on the web about having the unload call throw an ...
    (microsoft.public.dotnet.framework)
  • Re: appdomain.unload
    ... unload causes rude aborts which forces all threads to terminate. ... The appdomain will then be unloaded. ... app domain incorrectly. ... appdomain.unload call fails and no exception is caught. ...
    (microsoft.public.dotnet.framework)
  • Re: Global assembly cache and memory
    ... Each ASP.NET web application will live in an appdomain dedicated to ... the web app. ... Still - since static variables are scoped to a single ... if you put the DLL into the GAC then why can't the actual CODE ...
    (microsoft.public.dotnet.framework.aspnet)