# Cannot write to a closed TextWriter

**URL:** <https://forum.litium.com/t/cannot-write-to-a-closed-textwriter/1086>\
**Category:** Questions\
**Created:** [September 7, 2019, 2:46am UTC](https://forum.litium.com/t/cannot-write-to-a-closed-textwriter/1086 "2019-09-07T02:46:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rikard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/rikard/32/147_2.png) [@Rikard](https://forum.litium.com/u/Rikard)\
**Post date:** [September 7, 2019, 2:46am UTC](https://forum.litium.com/t/cannot-write-to-a-closed-textwriter/1086/1 "2019-09-07T02:46:38Z")

</div>

I keep finding this exception in my logs in multiple Litium projects:

System.ObjectDisposedException: Cannot write to a closed TextWriter.  
at [System.IO](http://System.IO).\_\_Error.WriterClosed()  
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)  
at Litium.Web.Products.PriceAgents.PriceAgentHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context)

Am I doing something wrong or is this a bug?

Litium version: 7.2.3

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [September 8, 2019, 10:25am UTC](https://forum.litium.com/t/cannot-write-to-a-closed-textwriter/1086/2 "2019-09-08T10:25:57Z")

</div>

It’s not a know bug, do you have any replication steps that we can use to replicate the issue?

Regarding to the code I can see two scenarios when this can happen:

1. If the price agent is closing the stream inside the render method.
2. If the client disconnects from server during processing.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [October 6, 2019, 10:27am UTC](https://forum.litium.com/t/cannot-write-to-a-closed-textwriter/1086/3 "2019-10-06T10:27:58Z")

</div>

Closed on October 6, 2019, 10:27am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
