Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. There is no Unicode byte order mark. Cannot switch to Unicode.

There is no Unicode byte order mark. Cannot switch to Unicode.

Scheduled Pinned Locked Moved .NET (Core and Framework)
comxmljsonhelp
2 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michele Smith
    wrote on last edited by
    #1

    Hello, I am receiving the error message:

    There is no Unicode byte order mark. Cannot switch to Unicode

    in this XML segment:

    There is no Unicode byte order mark. Cannot switch to Unicode.

    It occurs on the final line of this method:

    private async Task QueryOrders(string key, string accountName)
    {
    string XMLstring = CalculateOrderQueryXML(key, accountName);
    StringContent stringcontent = new StringContent(XMLstring);
    stringcontent.Headers.ContentType.MediaType = "text/XML";
    HttpResponseMessage response = await http.PostAsync("https://www.mywebsite.com/shared/xml/orderquery.rest", stringcontent);

            /\*string for response\*/
            string ResponseString = await response.Content.ReadAsStringAsync();
    
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(ResponseString);
    
            return xml.OuterXml;
    
        }
    
    Richard DeemingR 1 Reply Last reply
    0
    • M Michele Smith

      Hello, I am receiving the error message:

      There is no Unicode byte order mark. Cannot switch to Unicode

      in this XML segment:

      There is no Unicode byte order mark. Cannot switch to Unicode.

      It occurs on the final line of this method:

      private async Task QueryOrders(string key, string accountName)
      {
      string XMLstring = CalculateOrderQueryXML(key, accountName);
      StringContent stringcontent = new StringContent(XMLstring);
      stringcontent.Headers.ContentType.MediaType = "text/XML";
      HttpResponseMessage response = await http.PostAsync("https://www.mywebsite.com/shared/xml/orderquery.rest", stringcontent);

              /\*string for response\*/
              string ResponseString = await response.Content.ReadAsStringAsync();
      
              XmlDocument xml = new XmlDocument();
              xml.LoadXml(ResponseString);
      
              return xml.OuterXml;
      
          }
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Either the remote service is expecting Unicode data, or your generated XML has specified that it's using Unicode. Try sending the request with the Unicode encoding:

      string xmlString = CalculateOrderQueryXML(key, accountName);
      StringContent stringContent = new StringContent(xmlString, System.Text.Encoding.Unicode, System.Net.Mime.MediaTypeNames.Text.Xml);
      using (HttpResponseMessage response = await http.PostAsync("https://www.mywebsite.com/shared/xml/orderquery.rest", stringContent))
      {
      string responseString = await response.Content.ReadAsStringAsync();
      XmlDocument xml = new XmlDocument();
      xml.LoadXml(responseString);
      return xml.OuterXml;
      }

      If that doesn't work, then you'll need to check the result of your CalculateOrderQueryXML method.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups