Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to cast object of type 'Microsoft.OData.Edm.Csdl.CsdlSemantics.UnresolvedType' to type 'Microsoft.OData.Edm.IEdmCollectionType'

In Visual Studio 2013 I'm consuming an OData V4 endpoint using OData Client Code Generator found in Nuget. Unexpectedly this week the t4 template gave the error: Unable to cast object of type 'Microsoft.OData.Edm.Csdl.CsdlSemantics.UnresolvedType' to type 'Microsoft.OData.Edm.IEdmCollectionType'.

I have 7 OData endpoints I am working with and only one of them had an update on the back-end that required resaving the *.tt file. Upon saving the error appeared and left the output *.cs file blank. I then tried saving one of the *.tt files that had no model changes at the OData endpoint to see how it behaved. The thought process was that perhaps the change in the model at the endpoint somehow was incompatible with the client code generator. Unfortunately that one failed and produced a blank *.cs file as well with the same error.

Luckily everything is versioned with git and I was able to roll back the files to keep the project running.

Placing this here in case anyone else upgrades their OData Client Code Generator and gets frustrated.

like image 310
Pynt Avatar asked Mar 14 '23 17:03

Pynt


1 Answers

The problem turned out to be an upgrade from: OData Client T4 Template ver. 2.2.0 to OData Client T4 Template ver. 2.4.0

Between the versions a few new items are added that make your old *.TTInclude files useless.

STEPS TO REMEDY THE ISSUE

  • You can simply copy your settings from the old *.tt files like the MetadataDocumentUri, and NamespacePrefix
  • Delete the old *.tt file, and *.ttinclude file as the *.ttinclude is no longer compatible
  • Create a new file with the desired name (using Add > New Item > OData Client)
  • Paste the previously copied settings into place, and hit save

The above steps should resolve the issue.

Some of the changes I noticed with a diff on one of the ttincludes.

A new namespace was added to the ttinclude

<#@ Import Namespace="Microsoft.OData.Edm.Vocabularies.Community.V1" #>

A new DeclaredValueTerm was added:

tmp.FindDeclaredValueTerm(AlternateKeysVocabularyConstants.AlternateKeys) != null)

A new abstract method:

internal abstract void WriteEntityTypeAttribute();

And a few other miscellaneous items that makes your prior templates invalid. Hope this helps for anyone that upgrades the OData Client Code Generator for OData V4.

like image 128
Pynt Avatar answered Apr 29 '23 17:04

Pynt