ODataConnectedService icon indicating copy to clipboard operation
ODataConnectedService copied to clipboard

Could not get CLR type name for EDM type Edm.Untyped

Open Yahya0007 opened this issue 3 years ago • 3 comments

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

image

Yahya0007 avatar Feb 15 '22 13:02 Yahya0007

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.

habbes avatar Feb 22 '22 16:02 habbes

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

image

Yahya0007 avatar Feb 22 '22 16:02 Yahya0007

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 XPWeakReference complex type as an open type by adding the attribute IsOpen="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

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?

habbes avatar Feb 23 '22 08:02 habbes

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

lero-zhu avatar Dec 19 '23 09:12 lero-zhu