0

I was recently working on a project that required using Xml so I naturally used LINQ-to-XML to load my documents.

Unfortunately, as soon as I used the XDocument.Load method, I encountered this dreaded error message:

Data at the root level is invalid. Line 1, position 1.

This error is thrown only in prod environment but not in local

doc = XDocument.Load("C:\\Documents\\analyse\\InterBatch.ini");

XElement rootNode = doc.Element(Constant.NODE_CONFIGURATION);

fichierInstall.Base = this.ReadNodeBase(rootNode, Constant.NODE_BASE);
fichierInstall.Log = this.ReadNodeLog(rootNode, Constant.NODE_LOG);
fichierInstall.PathEntree = this.ReadNodePathEntree(rootNode, Constant.NODE_PATH_ENTREE);
fichierInstall.PathSortie = this.ReadNodePathSortie(rootNode, Constant.NODE_PATH_SORTIE);

any idea about the issue?

thank you

Alex K.
  • 171,639
  • 30
  • 264
  • 288
wbnani
  • 1
  • 2
  • 5
    `InterBatch.ini` does not look like its an XML file ... If it does actually contain XML what does it look like? – Alex K. May 16 '19 at 15:36
  • the file looks like `code`[Base] ConnectionStringOracleSIG = "dsn=SIG;uid=USER_AS;pwd=USER_AS" ConnectionStringOracle = "dsn=UTASS;uid=UTASS_user;pwd=UTASS_user" [PathEntree] PathFichier = "D:\wwwroot\Donnees\EnEcriture\Batch\Sortie\relance.dat" [PathSortie] PathFichier = "D:\WWWRoot\Donnees\EnEcriture\Sortie\Relance_UT_Fac.txt" [Log] CheminLog = "D:\WWWRootLog\" `code` – wbnani May 17 '19 at 10:27
  • 1
    Well that's an INI file not an XML file - they are completely different formats. [Reading/writing an INI file](https://stackoverflow.com/questions/217902/reading-writing-an-ini-file) – Alex K. May 17 '19 at 10:34
  • this is why the exception is thrown? – wbnani May 17 '19 at 11:27
  • 1
    Yes, the *"Data at the root level is invalid"* error is because XDocument expects XML but your giving it something completely different that it can't understand. – Alex K. May 17 '19 at 11:33

0 Answers0