Thank you for reaching out to Microsoft Q&A
This behavior is typically caused by shared mutable state being reused across Azure Function invocations. Reusing an EdiReader,X12Reader,EdifactReader instance across requests aren’t documented as thread‑safe.
- Reusing a
Stream(e.g., aMemory Stream) and forgetting to resetPositionto0 orappending to the same static stream—first run looks fine, later runs read wrong content. - Mutating global EDIFabric configuration (e.g., separators,
ReaderSettings, template assembly name) in static fields during one invocation that then affects the next.
To resolve this issue:
Create streams and readers per invocation and dispose them immediately:
[Function("ConvertEdi")]
public async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)
{
var input = await new StreamReader(req.Body).ReadToEndAsync();
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(input));
using var reader = new X12Reader(stream, "EdiFabric.Templates.X12");
var items = reader.ReadToEnd();
var xml = string.Join("\n", items.Select(i => i.Serialize().ToString()));
var res = req.CreateResponse();
await res.WriteStringAsync(xml);
return res;
}
Enable Logging to find out the cause:
Log a hash of the output per invocation
Adjust your Program.cs to give Information Logs.
_log.LogInformation("Output hash: {hash}", SHA256.HashData(Encoding.UTF8.GetBytes(xml)));
Correlate hashes across calls in Application Insights and find why the invocation is not happening.
You can monitor function logs by running KQL query: https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/azure-functions/monitor-functions.md and get more insights.