简体   繁体   English

无法将类型为“Microsoft.OData.Edm.Csdl.CsdlSemantics.UnresolvedType”的对象强制转换为“Microsoft.OData.Edm.IEdmCollectionType”

[英]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 解决问题的步骤

  • You can simply copy your settings from the old *.tt files like the MetadataDocumentUri, and NamespacePrefix 您只需从旧的* .tt文件复制您的设置,如MetadataDocumentUri和NamespacePrefix
  • Delete the old *.tt file, and *.ttinclude file as the *.ttinclude is no longer compatible 删除旧的* .tt文件和* .ttinclude文件,因为* .ttinclude不再兼容
  • Create a new file with the desired name (using Add > New Item > OData Client) 使用所需名称创建一个新文件(使用“添加”>“新建项”>“OData客户端”)
  • 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 在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.

相关问题 CSDL / EDM模型用于查询OData数据集的目的? - Purpose of csdl/edm model for querying an odata dataset? 反序列化Microsoft.OData.Edm.Date - Deserializing Microsoft.OData.Edm.Date 无法将DataServiceOrderedQuery类型的对象强制转换为Microsoft.OData.Client.DataServiceCollection类型 - Unable to cast object of type DataServiceOrderedQuery to type Microsoft.OData.Client.DataServiceCollection 如何找到OData edm模型类型到clr类型的映射? - How to find mapping of OData edm model type to clr type? 无法将类型为System.String的值转换为OData类型[Edm.Guid Nullable = True] - Unable to convert value of type System.String to OData type [Edm.Guid Nullable=True] 具有Microsoft.OData.Edm.Date参数的OData函数导致Swashbuckle错误 - OData function with Microsoft.OData.Edm.Date parameters causing error in Swashbuckle 在给定 Microsoft.Odata.Edm.IEdmModel 的情况下,如何确定绑定操作(函数或操作)所属的 EntitySet? - How can I determine the EntitySet that an bound Operation (function or action) belongs to given a Microsoft.Odata.Edm.IEdmModel? 在Microsoft.OData.Edm.Date和System.Nullable System.DateTimeOffset类型之间没有定义强制运算符。 - No coercion operator is defined between types Microsoft.OData.Edm.Date and System.Nullable System.DateTimeOffset odata自定义函数参数的短数据类型(Edm.Int16) - short data type (Edm.Int16) for odata custom function parameter 无法将类型“ System.Int32”强制转换为类型“ System.Object”。 LINQ to Entities仅支持强制转换EDM基本类型或枚举类型 - Unable to cast the type 'System.Int32' to type'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM