OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
675 stars 348 forks source link

Business Central Cloud "24.1.18927.19282" breaking changes #3003

Closed MikkelGlerup closed 3 weeks ago

MikkelGlerup commented 3 weeks ago

Using the client to connect and retrieve data from Business Central Cloud 24.1.18927.19282 will break and throw the error System.InvalidOperationException: 'This operation is only valid on generic types.'

This exception was originally thrown at this call stack:
    System.RuntimeType.GetGenericTypeDefinition() in RuntimeType.cs
    Microsoft.OData.Client.Metadata.ODataTypeInfo.GetKeyProperties()
    Microsoft.OData.Client.Metadata.ODataTypeInfo.KeyProperties.get()
    [Call Stack Truncated]

Assemblies affected

Microsoft.Odata.Client 7.0.0 and up Microsoft.Odata.Core 7.0.0 and up Microsoft.Odata.Edm 7.0.0 and up

Reproduce steps

Make any query request with an Odata context to a business Central Cloud version 24.1.18927.19282 and up var linesQuery = new DataServiceCollection<ExtendedSalesInvoiceLine?>(_CustomApiContext.ExtendedSalesInvoiceLines.Where(s => s.DocumentId == salesOrder.Id)); this line of code will cause this to throw an excpetion

Expected result

A list of SalesInvoiceLines that matches the given id.

Actual result

Code throws exception

This exception was originally thrown at this call stack:
    System.RuntimeType.GetGenericTypeDefinition() in RuntimeType.cs
    Microsoft.OData.Client.Metadata.ODataTypeInfo.GetKeyProperties()
    Microsoft.OData.Client.Metadata.ODataTypeInfo.KeyProperties.get()
    Microsoft.OData.Client.Metadata.ClientTypeUtil.GetKeyPropertiesOnType(System.Type, out bool)
    Microsoft.OData.Client.ClientEdmModel.GetTypeHierarchy(System.Type, out System.Reflection.PropertyInfo[], out bool)
    Microsoft.OData.Client.ClientEdmModel.GetOrCreateEdmType(System.Type)
    Microsoft.OData.Client.ClientEdmModel.CreateEdmProperty(Microsoft.OData.Edm.IEdmStructuredType, System.Reflection.PropertyInfo)
    Microsoft.OData.Client.ClientEdmModel.GetOrCreateEdmTypeInternal.AnonymousMethod__0(Microsoft.OData.Client.Providers.EdmEntityTypeWithDelayLoadedProperties)
    Microsoft.OData.Client.Providers.EdmEntityTypeWithDelayLoadedProperties.EnsurePropertyLoaded()
    Microsoft.OData.Client.Providers.EdmEntityTypeWithDelayLoadedProperties.DeclaredProperties.get()
    ...
    [Call Stack Truncated]

Additional detail

I have tested and confirmed that if the code is run towards version Business Central version 24.0.16410.17628 and below it will work, thus leading me to believe the issue it with Odata.

Business Central will force update all environment latest 15 july.