长度不能小于零。参数名称:OData Client

时间:2018-11-28 13:13:18

标签: dynamics-crm odata dynamics-365

我正在使用OData客户端从D365 AX获取数据。以下是有问题的代码

var test = context.Employees
                    .AddQueryOption("$filter", $"EmployeeNumber eq '{query.EmployeeNumber}'");
                var result = await test.ExecuteAsync();

我遇到以下异常

  

消息:System.ArgumentOutOfRangeException:长度不能小于   大于零。参数名称:length堆栈跟踪:               在System.String.Substring(Int32 startIndex,Int32长度)             在Microsoft.OData.TypeUtils.ParseQualifiedTypeName(StringqualifiedTypeName,String&namespaceName,String&typeName,Boolean&isCollection)              在Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ResolveType(字符串类型名称,函数3 clientCustomTypeResolver, Boolean throwIfMetadataConflict) at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ParseContextUriFragment(String fragment, Func 3 clientCustomTypeResolver,布尔型throwIfMetadataConflict,布尔型和未声明)处               在Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ParseContextUri(ODataPayloadKind ExpectedPayloadKind,Func 3 clientCustomTypeResolver, Boolean throwIfMetadataConflict) at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.Parse(IEdmModel model, String contextUriFromPayload, ODataPayloadKind payloadKind, Func 3 clientCustomTypeResolver,Boolean needParseFragment,布尔throwIfMetadataConflict)中            在Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ReadPayloadStart(ODataPayloadKind payloadKind,PropertyAndAnnotationCollector propertyAndAnnotationCollector,布尔值isReadingNestedPayload,布尔值allowEmptyPayload)              在Microsoft.OData.JsonLight.ODataJsonLightPayloadKindDetectionDeserializer.DetectPayloadKind(ODataPayloadKindDetectionInfo detectionInfo)               在Microsoft.OData.JsonLight.ODataJsonLightInputContext.DetectPayloadKind(ODataPayloadKindDetectionInfo detectionInfo)              在Microsoft.OData.Json.ODataJsonFormat.DetectPayloadKindImplementation(ODataMessageInfo messageInfo,ODataMessageReaderSettings设置)处              在Microsoft.OData.Json.ODataJsonFormat.DetectPayloadKind(ODataMessageInfo messageInfo,ODataMessageReaderSettings设置)             在Microsoft.OData.ODataMessageReader.DetectPayloadKind()             在Microsoft.OData.Client.Materialization.ODataMaterializer.CreateODataMessageReader(IODataResponseMessage responseMessage,ResponseInfo responseInfo,ODataPayloadKind&payloadKind)               在Microsoft.OData.Client.Materialization.ODataMaterializer.CreateMaterializerForMessage(IODataResponseMessage responseMessage,ResponseInfo responseInfo,类型materializerType,QueryComponents queryComponents,ProjectionPlan计划,ODataPayloadKind有效负载类型)              在Microsoft.OData.Client.MaterializeAtom..ctor(ResponseInfo responseInfo,QueryComponents queryComponents,ProjectionPlan计划,IODataResponseMessage responseMessage,ODataPayloadKind payloadKind)              在Microsoft.OData.Client.QueryResult.CreateMaterializer(ProjectionPlan计划,ODataPayloadKind有效负载类型)              在Microsoft.OData.Client.QueryResult.ProcessResult [TElement](ProjectionPlan计划)            在Microsoft.OData.Client.DataServiceRequest.EndExecute [TElement](对象源,DataServiceContext上下文,String方法,IAsyncResult asyncResult)              在Microsoft.OData.Client.DataServiceQuery 1.EndExecute(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar,Func 2 endFunction, Action 1 endAction,Task`1 promise,Boolean requiredSynchronization)中          ---从上一个引发异常的位置开始的堆栈跟踪---

Kinldy帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

您的edmx字符串与OData V4客户端代码生成器生成的客户端代码之间似乎存在冲突。我遇到了同样的错误,原因是我将edmx字符串存储在一个单独的文件中,并且我正在使用该文件的旧版本。最终,更新edmx字符串文件解决了该错误。