web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Odata utility compile error : cannot convert from 'System.Xml.XmlReader' to 'System.Collections.Generic.IEnumerable<System.Xml.XmlReader>

(0) ShareShare
ReportReport
Posted on by

Hi,

I have created OdataUtility to connect with D365FO.

I have installed Odata client Generator V4 and added OdataClient.tt file and set metadataDocumentUri to appropriate URL.

now it generated OdataClient.cs but when i try to build the solution, it throws below error. Please help if you know how to fix it. Thanks.

pastedimage1603979775779v2.png

~ Vikky

  • nmaenpaa Profile Picture
    101,174 Moderator on at

    Could you check the code lines where the errors come from? And also share your code with us?

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,429 on at

    Hi Vikky,

    Try replacing the "LoadModelFromString" method in OdataClient.cs with this code -

    private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString()
    {
        global::System.Xml.XmlReader reader = CreateXmlReader(Edmx);
        try
        {
            return global::Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader);
        }
        finally
        {
            ((global::System.IDisposable)(reader)).Dispose();
        }
    }

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,099 on at

    Hi Vikky,

    Are you using demo project https://github.com/microsoft/Dynamics-AX-Integration/tree/master/ServiceSamples/ODataUtility ?

    I recommend you not to use oDataUtility as it looks outdated, but create a new connected service with the latest version of oData generator + update oData.Client library to the latest version.

    www.atomicax.com/.../part-1-getting-connected-vs2017-and-connected-services

  • VRD Profile Picture
    on at

    Hi Nikolaos,

    It fails at below line

    return global::System.Xml.XmlReader.Create(new global::System.IO.StringReader(edmxToParse));

  • VRD Profile Picture
    on at

    Hi Gunjan,

    Thanks for your reply, but what is the 'Edmx' variable? Also, it fails at my end saying Microsoft.odata.Edm.csdl  not found in the assembly. Are you missing a reference?

    ~ Vikky

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,429 on at

    Hi Vikky,

    What version of Odata are you using? Please Try CsdlReader. This solution was provided by MS last time we had this issue. Please try this and check if you can compile successfully

    private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString()
    {
        global::System.Xml.XmlReader reader = CreateXmlReader(Edmx);
        try
        {
            return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader);
        }
        finally
        {
            ((global::System.IDisposable)(reader)).Dispose();
        }
    }

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,099 on at

    Hi Vikky,

    Manual fixing of auto-generated file OdataClient.cs will not help you too much in this case as next time when you refresh metadata you will get the same issue as all your manual changes wwill be wiped from the file.

    There are different T4 templates are used for older and newer oData generator versions to generate .net code in OdataClient.cs. If you want to have a permanent fix you need to re-add the connected service or fix the T4 template (oDataClient.ttinclude).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 213

#3
Subra Profile Picture

Subra 200 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans