Dynamics 365 finance and operations ODATA consuming - Length cannot be less than zero


When you consume a custom data entity, you get an error

errorSystem.ArgumentOutOfRangeException : Length cannot be less than zero” and it works fine for standard data entities. {:.error}


The reason is the temporary XML file where the metadata stored which mismatches with the metadata from https://<yourenvironment>$metadata

You can follow this post to understand how to create the XML file.

If you try to regenerate the metadata by saving the file, the XML will be accumulated, and the error keeps happening. The resolution here is simply delete it and regenerate metadata again by saving the file


Thank you for reading.