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 :
Dynamics 365 Community / Forums / Finance forum / Odata integration erro...
Finance forum

Odata integration error - The type initializer for 'GeneratedEdmModel' threw an exception.

(0) ShareShare
ReportReport
Posted on by 10

Hi 

When are trying to access OData service using C# code, while creating Context object i am facing following mentioned exception. 

Anyhelp will be very helpful for me. 

code :- 

public static string ODataEntityPath = ClientConfiguration.Default.UriString + "data";

Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
var context = new Resources(oDataUri);


context.SendingRequest2 += new EventHandler<SendingRequest2EventArgs>(delegate (object sender, SendingRequest2EventArgs e)
{
var authenticationHeader = OAuthHelper.GetAuthenticationHeader();
e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
});
var hvsSi = context.HVSSalesInvoices;
hvsSi = hvsSi.AddQueryOption("cross company", "true");
//hvsSi = hvsSi.AddQueryOption("$filter",String.Format("dataAreaId eq '{0}'","HVHS"));
var hvsOutput = hvsSi.Execute() as QueryOperationResponse<HVSSalesInvoice>;

An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.OData.Client.dll

Additional information: The type initializer for 'GeneratedEdmModel' threw an exception.
Inner execption :- {"Name cannot begin with the '4' character, hexadecimal value 0x34. Line 1, position 22.; "}

Stack trace
at OdataHVS.Microsoft.Dynamics.DataEntities.Resources.GeneratedEdmModel.GetInstance()
at Microsoft.OData.Client.DataServiceClientFormat.get_ServiceModel()
at Microsoft.OData.Client.DataServiceClientFormat.UseJson()
at OdataHVS.Microsoft.Dynamics.DataEntities.Resources..ctor(Uri serviceRoot) in C:\Users\Admin8ea7312fb5\documents\visual studio 2015\Projects\OdataHVS\OdataHVS\ODataClient1.cs:line 31
at OdataHVS.Program.Main(String[] args) in C:\Users\Admin8ea7312fb5\documents\visual studio 2015\Projects\OdataHVS\OdataHVS\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

  • RV Shwetha Profile Picture
    10 on at

    Any help ?

  • WolterKaper Profile Picture
    on at

    This question has been asked before by Smit Patel and he found an answer:

    https://community.dynamics.com/365/financeandoperations/f/765/p/293972/881868#881868

  • Suggested answer
    Jie G Profile Picture
    Microsoft Employee on at

    Hi Ashish Goswami,

    Please debug into the inner exception to see what is happening and then you should have the clue to solve this issue.

  • Mohammed Altaf Profile Picture
    435 on at

    Hi Ashish Goswami,

    How did you able to solve the issue, please share.

    I am also facing the same issue.

    Thanks.

  • Mohammed Altaf Profile Picture
    435 on at

    Its resolved.

    I followed below link.

    community.dynamics.com/.../881868

    Thanks

  • Community Member Profile Picture
    on at

    Hi,

    I followed this link community.dynamics.com/.../881868

    in OdataClient.cs Filepath already contains the value which i set in odataClient.tt file but m still getting error please help me to resolve the issues

  • Suggested answer
    Community Member Profile Picture
    on at

    have you installed OData client code generator in VS?

    if not it could be the root cause

  • Community Member Profile Picture
    on at

    Hi Rahul,

    I have installed odata client code generator please refer the below screen shot

    ClientCodeGeneratorInstallation.png

  • Suggested answer
    Community Member Profile Picture
    on at

    you may take a backup of the tt file and delete it and build the entire solution and let it get generated automatically

    the tt file links with your metadata

    pls regenerate tt and suggest

  • Community Member Profile Picture
    on at

    Hi Rahul,

    Thank you for the response.

    As you said, I have deleted the Following files

    ODataClient.tt which cascade and delete the ODataClient.cs 

    OdataClient.ttinclude

    after this

      i recreate the ODataClient.tt and inserts the values for MetaDataDocumentURI and TempFilePath 

      Built the library --> Generated the .cs file where file path has value which is same as the value that i set in the OdataClient.tt

      when i run the odata console application it throws me the same error.

    Please help me to resolve the error.

    4760.Error.png

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans