Buck3tt
Buck3tt
CC#
Created by Buck3tt on 3/27/2025 in #help
Fetching XML files from Azure Storage Explorer sometime fails
So for work we have a Azure Storage Explorer Fileshare where the customer sends XML files. Our Job fetches files from this fileshare every ~20 minutes maybe. Some files works fine and some just straight up fails with this code
var xmlFileByteArray = _azureHelper.GetFileBytes(fileName, sourceDirectory);

if (xmlFileByteArray is null)
{
return;
}

var reader = new StreamReader(new MemoryStream(xmlFileByteArray));
var xmlDocument = new XmlDocument();
xmlDocument.Load(reader);
var xmlFileByteArray = _azureHelper.GetFileBytes(fileName, sourceDirectory);

if (xmlFileByteArray is null)
{
return;
}

var reader = new StreamReader(new MemoryStream(xmlFileByteArray));
var xmlDocument = new XmlDocument();
xmlDocument.Load(reader);
And xmlDocument just says
System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'
System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'
The weird part is, when I locally debug it, fetch the correct file and run the same code, it doesn't fail. How could this be? They are named "123-1345.xml" or similar in the share and looks fine in notepad ++ or whatever program. Could there be some sort of "buffer" time that the file hasn't fully transformed in to a xml file yet or similar? Any help is appriciated
6 replies
CC#
Created by Buck3tt on 11/28/2022 in #help
❔ Somewhat advanced check for ids in foreach, remove duplicated
Hi! Right now im doing somewhat of a "complex" (at least for me to understand) check of id's to remove, and wanna ask if i can do this code example simpler, or shorter, cuz it feels like i could, but cant think of how
private List<int> CheckIfIdsIsInHigher
Hierarchy(List<LowerModel> allIds, List<string> higherHierachyIds)

var idsToRemove = new List<int>();
var idsToNotRemove = new List<int>();

foreach (var highIds in higherHierachyIds)
{
foreach (var ids in allIds)
{
if (!DoesIdExistInHigherHierachyModel(int.Parse(highId), ids.Id))
{
if (!idsToRemove.Contains(ids.Id))
{
idsToRemove.Add(ids.Id);
}
}
else
{
idsToNotRemove.Add(ids.Id);
}
}
}
var result = idsToRemove.Except(idsToNotRemove).ToList();
return result;
private List<int> CheckIfIdsIsInHigher
Hierarchy(List<LowerModel> allIds, List<string> higherHierachyIds)

var idsToRemove = new List<int>();
var idsToNotRemove = new List<int>();

foreach (var highIds in higherHierachyIds)
{
foreach (var ids in allIds)
{
if (!DoesIdExistInHigherHierachyModel(int.Parse(highId), ids.Id))
{
if (!idsToRemove.Contains(ids.Id))
{
idsToRemove.Add(ids.Id);
}
}
else
{
idsToNotRemove.Add(ids.Id);
}
}
}
var result = idsToRemove.Except(idsToNotRemove).ToList();
return result;
Since i tried to combine
if(!DoesIdExistInHigherHierachyModel(int.Parse(highId), ids.Id) && !idsToRemove.Contains(ids.Id))
if(!DoesIdExistInHigherHierachyModel(int.Parse(highId), ids.Id) && !idsToRemove.Contains(ids.Id))
Doesnt give the same result Thanks in advance
22 replies