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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With