MONO System.Xml.XmlException: Data at the root level is invalid. Line 1, position 681. RRS feed

  • Question

  • User-1776158581 posted

    I have written an application that the user can upload an excel file through angular to my c# web API, I then save the data locally on the server and return some information regarding the uploaded file. the user then uploads some more information and I read this file locally to accompany the users info to do a specific process.

    My problem comes when reading my file from my locally saved folder. in a .NET environment it works but when deployed to Docker on Linux I seem to always get the same issue

    System.Xml.XmlException: Data at the root level is invalid. Line 1, position 681.

    The strange thing is that it reads the stream from my angular front-end no problem (Also dockerised) and it saves the file correctly too. I pulled the saved file from the docker container and it opens no problem. its only when reading the file stream does this error occur.

    Below is the portion of the code that reads the local file. try/catch and Console.writeline is how I can quickly see whats happening in mono without tailing logs so please dont pay attention to the actual code style.

     public void PostAssets([FromUri] string fileName, string email, [FromBody] dynamic jsonSchema)
                    $"Getting file : {fileName} from {AppDomain.CurrentDomain.BaseDirectory}SavedFiles as : {fileName}.xlsx");
                Logger.Debug("Getting locally stored file with name: " + fileName);
                //var stream = File.Open($"{AppDomain.CurrentDomain.BaseDirectory}SavedFiles/{fileName}.xlsx",FileMode.Open, FileAccess.Read);
                Console.WriteLine("Received file stream from locally saved folder");
                IExcelDataReader excelReader = null;
                var byteArray = File.ReadAllBytes($"{AppDomain.CurrentDomain.BaseDirectory}SavedFiles/{fileName}.xlsx");
                var stream = new MemoryStream(byteArray);
                    if ($"{AppDomain.CurrentDomain.BaseDirectory}SavedFiles/{fileName}.xlsx".EndsWith(".xls"))
                        excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
                    if ($"{AppDomain.CurrentDomain.BaseDirectory}SavedFiles/{fileName}.xlsx".EndsWith(".xlsx"))
                        excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                catch (Exception e)
                    excelReader = null;

    I am using .net 4.5 and mono 4 and the excel library I am using is

      <package id="ExcelDataReader" version="" targetFramework="net45" />

    I am not compiling the code in linux my docker-compose just copies the dll's over.

    Any help would be appreciated

    Wednesday, June 15, 2016 2:22 PM


  • User-782232518 posted

    As that's a third party open source library, you should report to its developers via GitHub,


    Of course, you should provide as much information as possible so that the developers can reproduce this issue and research on their own.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 16, 2016 4:07 AM