3

The following code:

IDisposable d = ...
new WeakReference<IDisposable>(d);

Has started throwing the following exception on SOME machines. What could cause this?

System.Runtime.InteropServices.COMException: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

EDIT: the machines that experience the error are running Windows Server 2008 R2. Windows Server 2012 and desktop machines running windows 7 work fine. (this is true, but I now think a different issue is the relevant difference... see below).

EDIT: as an additional note, this occurred right after updating our codebase to Entity Framework 6.1.1.-beta1. In the above code, The IDisposable is a class which wraps an EF DbContext.

EDIT: why the votes to close?

EDIT: the stack trace of the failure ends at the WeakReference<T> constructor called in the above code:

at System.WeakReference`1..ctor(T target, Boolean trackResurrection)
// from here on down it's code we wrote/simple LINQ. None of this code has changed recently;
// we just upgraded to EF6 and saw this failure start happening
at Core.Data.EntityFrameworkDataContext.RegisterDependentDisposable(IDisposable child)
at Core.Data.ServiceFactory.GetConstructorParameter[TService](Type parameterType)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Core.Data.ServiceFactory.CreateService[TService]()
at MVC controller action method

EDIT: it turns out that the machines having issues with this were running AppDynamics. Uninstalling that seems to have removed the issue.

ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
  • Were you able to identify any similarities between the setups of these machines? – Thomas Levesque Jun 06 '14 at 21:03
  • The stack trace could be useful. – acelent Jun 07 '14 at 13:05
  • What is the actual expression in `...`? What apartment is the current thread in? Have you tried native debugging? – acelent Jun 09 '14 at 00:49
  • @PauloMadeira: `...` is an argument passed to the current method. In this case, it's a custom type that wraps `DbContext`. There's nothing special about it; it basically just exposes the `DbContext` methods. This is running in an ASP.NET web application; not sure what that means regarding apartment state. I haven't been able to try native debugging because I can't reproduce this on a machine I have that level of access to. – ChaseMedallion Jun 10 '14 at 13:08
  • @PauloMadeira: got a chance to post the full stack trace – ChaseMedallion Jun 10 '14 at 13:14
  • Perhaps someone else can provide you further help. It seems the constructor of `WeakReference` is validating the object for something, but I don't know if it does or what it would check. – acelent Jun 12 '14 at 14:08

0 Answers0