“Root element is missing” error but I have a root element

前端 未结 3 1071
遇见更好的自我
遇见更好的自我 2021-01-07 17:21

If anyone can explain why I\'m getting a \"Root element is missing\" error when my XML document (image attached) has a root element, they win a pony which fires lazers from

3条回答
  •  天涯浪人
    2021-01-07 17:46

    Reset the base stream's position each time it is read if you want to read from the beginning as stated earlier, but you don't have to re-create the stream each time.

    String xmlResource = Assembly.GetExecutingAssembly().GetName().Name + ".XML.IODeleter.xsd";
    configXsd = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(xmlResource));
    if (configXsd != null)
      {
        configXsd.BaseStream.Position = 0;
    
        File.WriteAllText(apppath + @"\" + Assembly.GetExecutingAssembly().GetName().Name + ".XML.IODeleter.xsd", configXsd.ReadToEnd());
      }
    

提交回复
热议问题