Could not get CLR type name for EDM type Edm.Untyped
Describe the bug
I am getting below error when adding an OData service. The offending code seems to be Edm.Untyped in data that is received from the metadata url (http://mydomain/api/odata/$metadata);
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="DevExpress.Xpo">
<ComplexType Name="XPWeakReference">
<Property Name="Target" Type="**Edm.Untyped**"/>
<Property Name="TargetType_" Type="DevExpress.Xpo.XPObjectType"/>
<Property Name="TargetKey_" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="XPObjectType">
<Property Name="TypeName" Type="Edm.String"/>
<Property Name="AssemblyName" Type="Edm.String"/>
</ComplexType>
</Schema>
Version of the Project affected
ODataConnectedService v0.13.0 VisualStudio Version v16.11.9 Microsoft.Odata.Client 7.10.0
To Reproduce
Trying adding the remote OData service using my own metadata url http://mydomain/api/odata/$metadata.
Expected behavior
No error.
Actual behavior
Error as per screen below.
Screenshots

Hi @Yahya0007 Is that a v4 service. It doesn't seem that we have good support for Edm.Untyped when generating code. Could you share about your use case and why you need to use EdmUntyped? Would Open Types and dynamic properties work for your scenario. The OData Connected Service has support for open types.
Hi
Thanks for coming back. I am using DevExpress’s Web API which I think is v4 https://docs.devexpress.com/eXpressAppFramework/403394/backend-web-api-service.
Their API returns Edm.Untyped via metadata url http://.../api/odata/$metadata for the XPWeakReference entity, as below. If I remove XPWeakReference entity from references it also removes my other related entities. Please see image link below at the end.
If somehow I can exclude XPWeakReference entity without excluding other related entities it will solve my problem.
Thanks
Regards

Hi @Yahya0007 the DevExpress link you have shared (I'm not familiar with the service) seems to suggest that their API is OData v4.0. According to the spec Edm.Untyped is supported in v4.01 but not v4.0.
In any case, I'm not sure if the OData core libraries support Edm.Untyped and how to handle properties of that type in C# classes. I will investigate that then get back here with a proposed way forward as far as the code generation is concerned: i.e. what's the appropriate thing to do when we encounter Edm.Untyped property:
- do we throw an exception (current behavior)
- do nothing and ignore the property
- generate a property of type
object(don't know if the core libraries support that) - treat the declaring entity type or complex type as an open type so that this property can be treated as a dynamic property
- something else
For the time being, I would suggest the following hack:
- Download the metadata from the service and save it into a file.
- Modify the file as follows:
- If you're sure you app is not going to use that property (i.e.
XPWeakReference.Target), then remove it from the schema file - If your app might use it, then remove the property but mark the
XPWeakReferencecomplex type as an open type by adding the attributeIsOpen="True" - Use OData Connected Service to generate code. Instead of passing a service endpoint, click "Browse" button to select the file saved on your local machine
- If you're sure you app is not going to use that property (i.e.
I am also curious about the fact that the Target property in XPWeakReference has Edm.Untyped as the type, but there's a separate TargetType_ property whose type is DevExpress.Xpo.XPObjectType. Do you know more about the meaning behind these properties and their intended use? Why isn't the type of XPWeakReferece.Target DevExpress.Xpo.XPObjectType?
I also encountered this problem. I referred to this link to build the Sever project, and then encountered the same error on the client side. Is there any solution? @habbes