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 6824177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:52:15+00:00 2026-05-26T21:52:15+00:00

I tried to phrase this as a generic question but realized I don’t know

  • 0

I tried to phrase this as a generic question but realized I don’t know enough, so here is the problem I’m having.

Here is a snippet from a console application:

public void Run()
{
    Run(Console.Out);
}

public void Run(TextWriter writer)
{
    DataTable customers = _quickBooksAdapter.GetTableData("Customer");
    customers.WriteXml(writer);
}

Then I run it from the console and use “>” to put it in a file.

c:\> QuickBooksETL extract US > qb_us.xml

If i try to load the result as I would normally:

var x = XDocument.Load("qb_us.xml");

I get the error:

Invalid character in the given encoding. Line 8, position 26.

So I tried to determine what .NET “thinks” it is using:

string path = @"\\ad1\accounting$\Xml\qb_us.xml"; 
StreamReader sr = new StreamReader(path);
sr.CurrentEncoding.Dump();

Result:

System.Text.UTF8Encoding 
BodyName utf-8
EncodingName Unicode (UTF-8)
HeaderName utf-8
WebName utf-8
WindowsCodePage 1200
IsBrowserDisplay True
IsBrowserSave True
IsMailNewsDisplay True
IsMailNewsSave True
IsSingleByte False
EncoderFallback 5EncoderReplacementFallback  
System.Text.EncoderReplacementFallback 
DefaultString �
MaxCharCount 1
DecoderFallback 5DecoderReplacementFallback  
System.Text.DecoderReplacementFallback 
DefaultString �
MaxCharCount 1
IsReadOnly True
CodePage 65001

Finally, I find by guessing that it works if I just explicitly say it’s ASCII:

string path = @"\\ad1\accounting$\Xml\qb_us.xml"; 
StreamReader sr = new StreamReader(path, Encoding.ASCII);
var x = XDocument.Load(sr);

Any thoughts on where am I going wrong would be greatly appreciated. I admit I have never taken the “deep dive” on character encodings, but I’m willing to put in the effort to get this right.

  • 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-05-26T21:52:15+00:00Added an answer on May 26, 2026 at 9:52 pm

    The simple answer is not to get the console involved. Write directly to the file from your code:

    public void Run(string filename)
    {
        DataTable customers = _quickBooksAdapter.GetTableData("Customer");
        customers.WriteXml(filename);
    }
    

    or create the TextWriter or Stream yourself and pass that in, e.g.

    public void Run(Stream output)
    {
        DataTable customers = _quickBooksAdapter.GetTableData("Customer");
        customers.WriteXml(output);
    }
    

    Note that by reading it as ASCII, you’ll basically be getting question marks for any non-ASCII character in the original data. IIRC, that’s the default behaviour of an encoding when it encounters binary data it can’t handle.

    Using a Stream it should default to writing out in UTF-8, and the XML declaration and the data within the file should match.

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

Sidebar

Related Questions

Sorry for the terrible Question Title, I don't know how to phrase this, feel
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
I've tried many different ways to phrase this question to google et al with
I tried searching for this but I'm not even sure how to phrase it
I tried asking this the other day, and admittedly did not phrase the question
Tried searching the site, but cannot find an answer to my problem: Lets say
I've tried several times to come with an answer to this question. I'm not
I know there's got to be a way to do this, but for the
First, this is a very basic question that I'm unsure of how to phrase.
this is really annoying me, i've tried looking up a solution but to no

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.