我正在使用 AutoRest 从 Swagger 定义文件自动生成 REST API 的 C# 类。
问题在于,当执行客户端类的initialize方法时,会抛出ArrayTypeMismatchException,代码如下:
SerializationSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
ContractResolver = new ReadOnlyJsonContractResolver(),
Converters = new List<JsonConverter>
{
new Iso8601TimeSpanConverter()
}
}
有问题的代码是添加到 JsonConverters 列表中的 Iso8601TimeSpanConverter。
顺便说一句,只有在 VSIX 包中运行此代码时才会发生这种情况。在独立应用程序上,它工作得很好。
我想知道这是否与 Newtonsoft.Json 的多个版本加载和碰撞有关?
有任何想法吗?
我遇到了同样的问题,但最终通过使用 app.config 统一 Newtonsoft.Json 绑定解决了这个问题。
<configuration>
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
问题是 Iso8601TimeSpanConverter 可能继承的 JsonConverter 版本与您在 AutoRest 上使用的版本不同。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)