How to avoid System.InvalidCastException: Unable to cast object of type 'Microsoft.OData.Edm.Library.AmbiguousTypeBinding' to type 'Microsoft.OData.Edm.IEdmCollectionType'.
https://community.dynamics.com/ax/b/dynamicsaxthehardway/archive/2018/04/07/how-to-avoid-system-invalidcastexception-unable-to-cast-object-of-type-39-microsoft-odata-edm-library-ambiguoustypebinding-39-to-type-39-microsoft-odata-edm-iedmcollectiontype-39
Problem:
When trying to extract metadata using Odata client you will get this error System.InvalidCastException: Unable to cast object of type 'Microsoft.OData.Edm.Library.AmbiguousTypeBinding' to type 'Microsoft.OData.Edm.IEdmCollectionType'.
Solution:
Problem:
When trying to extract metadata using Odata client you will get this error System.InvalidCastException: Unable to cast object of type 'Microsoft.OData.Edm.Library.AmbiguousTypeBinding' to type 'Microsoft.OData.Edm.IEdmCollectionType'.
Solution:
- Run the metadata link in a navigator : https://********.ax.dynamics.com/data/$metadata
- Wait until it finishes extracting, save it as xml file
- The actual problem is in metadata. There is an Enum with name "ItemType" and also the Data Entity with same name "ItemType". Due to which the proxy file is not generated due to same name and giving the error.The solution will be changing the name of Data Entity "ItemType" to "ItemTypes"
EntityType Name="ItemTypes"
and also do not forget to change the name in Entity Set in container.
EntitySet Name="ItemTypes" EntityType="Microsoft.Dynamics.DataEntities.ItemTypes"
We have tested the same and it works fine. - Use that file to generate the POCOs like : public const string MetadataDocumentUri = "File:///D:/metadata.xml";
Comments
Post a Comment