@@ -203,7 +203,10 @@ public Size BindAsObject(in BindContext context, object? value, ref object? writ
203203 // writeState pointing at a half-disposed object — they'd dispose it again.
204204 ( var current , writeState ) = ( writeState , null ) ;
205205 ( current as IDisposable ) ? . Dispose ( ) ;
206- if ( ! ReferenceEquals ( current , originalWriteState ) )
206+ // current==null with original!=null means an inner safety net (transparent wrapper case)
207+ // already disposed the original. Disposing again would double-dispose. The non-null branch
208+ // handles the genuine lifecycle-violation swap where current and original differ.
209+ if ( current is not null && ! ReferenceEquals ( current , originalWriteState ) )
207210 ( originalWriteState as IDisposable ) ? . Dispose ( ) ;
208211 throw ;
209212 }
@@ -377,7 +380,10 @@ public Size Bind(in BindContext context,
377380 // writeState pointing at a half-disposed object — they'd dispose it again.
378381 ( var current , writeState ) = ( writeState , null ) ;
379382 ( current as IDisposable ) ? . Dispose ( ) ;
380- if ( ! ReferenceEquals ( current , originalWriteState ) )
383+ // current==null with original!=null means an inner safety net (transparent wrapper case)
384+ // already disposed the original. Disposing again would double-dispose. The non-null branch
385+ // handles the genuine lifecycle-violation swap where current and original differ.
386+ if ( current is not null && ! ReferenceEquals ( current , originalWriteState ) )
381387 ( originalWriteState as IDisposable ) ? . Dispose ( ) ;
382388 throw ;
383389 }
0 commit comments