Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:52:42+00:00 2026-06-10T07:52:42+00:00

Edit: FYI for future readers, this issue has been fixed as of version 2.3.606.0

  • 0

Edit: FYI for future readers, this issue has been fixed as of version 2.3.606.0 of BitMiracle’s LibTiff.NET.

I’m using BitMiracle’s LibTiff.NET (version 2.3.605.0 and below) in my C# library (compiled at .NET 3.5 | x86) and keep getting this exception when I call ReadDirectory: System.ObjectDisposedException: Cannot write to a closed TextWriter

I realize that this seems to indicate that I have already disposed of my image before making the call…but I have not specifically done so. Is this a bug in the library or am I really missing something here?

Here is my code:

    public static bool IsTiffBiTonal(String tiffFilePath)
    {
        VerifyFileExistence(tiffFilePath);

        using (Tiff tiff = Tiff.Open(tiffFilePath, "r"))
        {
            do
            {
                if (tiff.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt() == 1)
                {
                    continue;
                }
                return false;
            }
            while (tiff.ReadDirectory()); //Error occurs here
        }
        return true;
    }

EDIT: Ok, I have more information after some further testing, this is only happening when I’m running my unit tests! Don’t know why that would change anything though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:52:44+00:00Added an answer on June 10, 2026 at 7:52 am

    Because of other threads talking about unit testing and getting this same error when trying to write to the console (ObjectDisposedException when outputting to console) I realized that the LibTiff.NET library was trying to write to the error console. After looking through the source code, I found that this code:

            using (TextWriter stderr = Console.Error)
            {
                ...
            }
    

    Because they were wrapping all of the writes to the error out in a using, it was disposing of the Console.Error object after the first write to the error out. This caused my error on the second time around (ReadDirectory does what calling Next on a linked list does). So I removed the using and the problem was fixed!

            TextWriter stderr = Console.Error;
            ...
    

    So, the lesson here: don’t dispose of your standard outputs 🙂

    I’ve asked another question regarding why they were ever allowed to dispose of the standard output in unit tests but not in other situations here: .NET – Why is disposing of standard output only allowed during unit tests?. If you have any answers to the question…please post it there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: iam using ajax to load text in my content that is why onload
EDIT : It turned out that this can only be done through an external
EDIT: Simple version of the question: I want to create server variables in the
Similar questions has been asked a lot. But, I think my situation is a
I have this set of Javascript code that works fine in IE (any version),
Background: I have a website (ASP.NET MVC) where users can write/edit/delete a review. Doing
-Edit- FYI.. I am converting b&w documents scanned in as greyscale or color. 1)The
EDIT: Sorry I forgot to mention, I'm not using the implemented sha512 crypt because
With reSharper -> Edit -> Generate Code -> Properties from this: private int _age;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.