![](/img/trans.png)
[英]Is it possible to use late binding on a COM object inside a T4 template?
[英]Is it possible to use NewtonSoft.Json inside a T4 template?
我想在T4模板中反序列化一些JSON。 我已經引用了程序集以及所有這些並且它看起來都很好但是當我稱之為:
var root = JsonConvert.DeserializeObject<RootObject>(response);
我明白了:
Error 4 Running transformation: System.TypeLoadException: Could not find Windows Runtime type 'Windows.Data.Json.IJsonValue'. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
--- End of inner exception stack trace ---
at Newtonsoft.Json.Converters.JsonValueConverter.CanConvert(Type objectType)
at Newtonsoft.Json.JsonSerializer.GetMatchingConverter(IList`1 converters, Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at Microsoft.VisualStudio.TextTemplating051377DF83FAD6CEB531E8C53BDF7AF0925D52AE4E0D72D32E8A27AD05041FA9D55204F2BCFCC44A6977B1EA4AD1DA5E9682BFE9EB924836019C6E14E1AED232.GeneratedTextTransformation.GetInfoForCountries() in c:\************\CalabashTestGeneration\Template1.tt:line 117
at Microsoft.VisualStudio.TextTemplating051377DF83FAD6CEB531E8C53BDF7AF0925D52AE4E0D72D32E8A27AD05041FA9D55204F2BCFCC44A6977B1EA4AD1DA5E9682BFE9EB924836019C6E14E1AED232.GeneratedTextTransformation.TransformText() in c:\****************\CalabashTestGeneration\Template1.tt:line 24 c:\*************\CalabashTestGeneration\Template1.tt 117 1 CalabashTestGeneration
這甚至可能嗎? 我不明白為什么T4不能使用newtonsoft,但這種暗示它不能!
我最終使用了restsharp - 似乎到目前為止工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.