Reputation: 89
I am using OData client to fetch the data from D365 AX. Following is the piece of code that is having the problem
var test = context.Employees
.AddQueryOption("$filter", $"EmployeeNumber eq '{query.EmployeeNumber}'");
var result = await test.ExecuteAsync();
I am getting the following exception
Message: System.ArgumentOutOfRangeException : Length cannot be less than zero. Parameter name: length Stack Trace: at System.String.Substring(Int32 startIndex, Int32 length) at Microsoft.OData.TypeUtils.ParseQualifiedTypeName(String qualifiedTypeName, String& namespaceName, String& typeName, Boolean& isCollection) at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ResolveType(String typeName, Func
3 clientCustomTypeResolver, Boolean throwIfMetadataConflict) at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ParseContextUriFragment(String fragment, Func
3 clientCustomTypeResolver, Boolean throwIfMetadataConflict, Boolean& isUndeclared) at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ParseContextUri(ODataPayloadKind expectedPayloadKind, Func3 clientCustomTypeResolver, Boolean throwIfMetadataConflict) at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.Parse(IEdmModel model, String contextUriFromPayload, ODataPayloadKind payloadKind, Func
3 clientCustomTypeResolver, Boolean needParseFragment, Boolean throwIfMetadataConflict) at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ReadPayloadStart(ODataPayloadKind payloadKind, PropertyAndAnnotationCollector propertyAndAnnotationCollector, Boolean isReadingNestedPayload, Boolean allowEmptyPayload) at Microsoft.OData.JsonLight.ODataJsonLightPayloadKindDetectionDeserializer.DetectPayloadKind(ODataPayloadKindDetectionInfo detectionInfo) at Microsoft.OData.JsonLight.ODataJsonLightInputContext.DetectPayloadKind(ODataPayloadKindDetectionInfo detectionInfo) at Microsoft.OData.Json.ODataJsonFormat.DetectPayloadKindImplementation(ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) at Microsoft.OData.Json.ODataJsonFormat.DetectPayloadKind(ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) at Microsoft.OData.ODataMessageReader.DetectPayloadKind() at Microsoft.OData.Client.Materialization.ODataMaterializer.CreateODataMessageReader(IODataResponseMessage responseMessage, ResponseInfo responseInfo, ODataPayloadKind& payloadKind) at Microsoft.OData.Client.Materialization.ODataMaterializer.CreateMaterializerForMessage(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Type materializerType, QueryComponents queryComponents, ProjectionPlan plan, ODataPayloadKind payloadKind) at Microsoft.OData.Client.MaterializeAtom..ctor(ResponseInfo responseInfo, QueryComponents queryComponents, ProjectionPlan plan, IODataResponseMessage responseMessage, ODataPayloadKind payloadKind) at Microsoft.OData.Client.QueryResult.CreateMaterializer(ProjectionPlan plan, ODataPayloadKind payloadKind) at Microsoft.OData.Client.QueryResult.ProcessResult[TElement](ProjectionPlan plan) at Microsoft.OData.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult) at Microsoft.OData.Client.DataServiceQuery1.EndExecute(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action
1 endAction, Task`1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown ---
Kinldy help me on this.
Upvotes: 1
Views: 1919
Reputation: 481
It seems like there is a conflict between your edmx string and client code generated by OData V4 Client Code Generator. I faced the same error and the reason was that I stored the edmx string in a separate file and I was using an old version of the file. Eventually, updating the edmx string file resolved the error.
Upvotes: 2