[英]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. 在Visual Studio 2013中,我使用Nuget中的OData客户端代码生成器来使用OData V4端点。 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'.
出乎意料的是,本周t4模板给出了错误:无法将类型为“Microsoft.OData.Edm.Csdl.CsdlSemantics.UnresolvedType”的对象强制转换为“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. 我正在使用7个OData端点,并且只有其中一个在后端需要重新保存* .tt文件的更新。 Upon saving the error appeared and left the output *.cs file blank.
保存后出现错误并将输出* .cs文件留空。 I then tried saving one of the *.tt files that had no model changes at the OData endpoint to see how it behaved.
然后,我尝试在OData端点保存一个没有模型更改的* .tt文件,以查看它的行为方式。 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.
不幸的是,一个失败并产生了一个空白的* .cs文件以及相同的错误。
Luckily everything is versioned with git and I was able to roll back the files to keep the project running. 幸运的是,所有内容都使用git进行版本控制,我能够回滚文件以保持项目正常运行。
Placing this here in case anyone else upgrades their OData Client Code Generator and gets frustrated. 将此放在此处以防其他任何人升级他们的OData客户端代码生成器并感到沮丧。
The problem turned out to be an upgrade from: OData Client T4 Template ver. 问题原来是从以下版本升级:OData Client T4 Template ver。 2.2.0 to OData Client T4 Template ver.
2.2.0到OData客户端T4模板版本。 2.4.0
2.4.0
Between the versions a few new items are added that make your old *.TTInclude files useless. 在版本之间添加了一些新项目,使您的旧* .TTInclude文件无效。
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 在ttinclude中添加了一个新的命名空间
<#@ Import Namespace="Microsoft.OData.Edm.Vocabularies.Community.V1" #>
A new DeclaredValueTerm was added: 添加了一个新的DeclaredValueTerm:
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.
希望这对任何为OData V4升级OData客户端代码生成器的人都有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.