Generated XML files don't validate against schema
Problem reported by Christer Kaivo-oja - 11/17/2022 at 2:58 PM

We are working on a (C# .NET6) project where we generate XML files using Liquid XML Objects generated classes. What probably makes our solution somewhat unusual is that we want to populate the instances of the Liquid generated classes using reflection.

While doing this, we have run into an issue where the serialized XML file isn't deterministic, and items in sequences get written out of order. We have ensured that the generated code uses the "Conformant" Generation Model, but the problem persists through that.

In order to debug the issue, we have created a simplified project that reproduces the error, and ran it on multiple machines (mix of Windows and Ubuntu Server), and the results differ on the different machines and execution modes (debug in visual studio, no debugging in visual studio, running the deployed app).

The debug project uses an "operation log" that has been generated to replicate behaviour from our real project. Using that, the debug project uses reflection methods to fill Liquid XML Objects with data and once done, it's serialized out to a file and the result is validated against the XSD schema.

The same process is done multiple times in a loop, and output files that do not validate against the schema are stored and this is marked on the console output. While the code is identical for every iteration of the loop, the outputs differ. Most executions we do will start to produce invalid XML files almost immediately (within the first 10 iterations), but one platform (a newly installed VM running Ubuntu Server) generated around 120 correct files after which it devolved into roughly 50% failure rate.

We have uploaded the project to Github if someone wants to reproduce the error on their end. It can be found here:


As a side-note, the problem appears to be triggered by the use of reflection. The project above also generates code for a non-reflection variant of the same process, which does not appear to generate invalid XML files if used. If absolutely necessary, generating code and compiling it in runtime could be a way to get around the issue but we would like to avoid that if possible (if nothing else, that's a big performance hit).

3 Replies

Reply to Thread
Liquid Support Replied
Employee Post

Thanks for your feedback and excellent example.

It looks like in .Net 6 GetProperties does not guarantee the order during reflection as discussed here:

We are looking into implementing our own ordering of properties. A fix should be available in a few days.

Liquid Support Replied
Employee Post Marked As Resolution

This issue has now been resolved in v20.2.0, and can be downloaded from our web site:

Note: You will need to regenerate the code after installing the new version, and ensure you are referencing the new v20.2.0 Nuget.

Christer Kaivo-oja Replied
We have double-checked on our end and it does indeed seem resolved. Huge thank you to your team for a a very fast turnaround time for a complex problem. We truly appreciate it!

Reply to Thread