diff --git a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs index b620a8f..61faf4b 100644 --- a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs @@ -23,6 +23,7 @@ namespace Capnp.Rpc // In order to distinguish state A from C, the member _refCount stores the reference count *plus one*. // Value 0 has the special meaning of being in state C. int _refCount = 1; + string _disposerStackTrace; ~RefCountingCapability() { @@ -68,7 +69,7 @@ namespace Capnp.Rpc { if (Interlocked.Increment(ref _refCount) <= 1) { - throw new ObjectDisposedException(nameof(ConsumedCapability)); + throw new ObjectDisposedException(nameof(ConsumedCapability), _disposerStackTrace); } } @@ -76,6 +77,8 @@ namespace Capnp.Rpc { if (1 >= Interlocked.Decrement(ref _refCount)) { + _disposerStackTrace = Environment.StackTrace; + Dispose(true); GC.SuppressFinalize(this); }