我有一些非常奇怪的问题。有了所有最新的Powerbi Nuget包装及其依赖关系的最新迭代,我得到以下例外:
Exception thrown: 'System.ArrayTypeMismatchException' in mscorlib.dll
Additional information: Attempted to access an element as a type incompatible with the array.
堆栈跟踪向我展示了:
at System.Collections.Generic.List`1.Add(T item)
at Microsoft.PowerBI.Api.V1.PowerBIClient.Initialize()
at Microsoft.PowerBI.Api.V1.PowerBIClient..ctor(ServiceClientCredentials credentials, DelegatingHandler[] handlers)
at Apps.Kinetic.Reports.Endpoint.Service.Reports.g1u0.GenerateAccessToken(String _Reference) in D:*masked*.cs:line 575
在尝试查看初始化时发现的PowerBiclient源代码时,它确实尝试将一类类型ISO8601TimesPanconVerter添加到JSONCONCONVERT列表中,只需在此处查看:
/// </summary>
private void Initialize()
{
this.Datasets = new Datasets(this);
this.Gateways = new Gateways(this);
this.Imports = new Imports(this);
this.Workspaces = new Workspaces(this);
this.Reports = new Reports(this);
this.BaseUri = new Uri("https://api.powerbi.com");
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()
}
};
DeserializationSettings = new JsonSerializerSettings
{
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
ContractResolver = new ReadOnlyJsonContractResolver(),
Converters = new List<JsonConverter>
{
new Iso8601TimeSpanConverter()
}
};
CustomInitialize();
}
我无法弄清楚为什么在演示示例中使用几个版本的演示样本中,它会完全工作。但是我确实知道,当我首先使用4.6.1中的常规.NET控制台应用程序时,我也可以使用它。但是现在,我使用.NET 4.6.1框架使用了.NET Core Console应用程序。除此之外,一切都很好。
这是问题的屏幕截图:
问题的屏幕截图
我发现该开发人员在一段时间前有类似问题,但与PowerBi无关。但是没有答案。
将ISO8601TimesPanconverter添加到JSONCONVERTER列表中抛出ArrayTyPemismatch异常
您提供的问题的链接现在包含一个提示,可以帮助我解决此问题。就我而言,这是由GAC中安装的多个版本的newtonsoft.json.dll引起的。在我配置了我的应用程序以解析库引用最新版本后,例外已经消失了。