【问题标题】:PowerBIClient generates System.ArrayTypeMismatchException under certain circumstancesPowerBIClient 在某些情况下会生成 System.ArrayTypeMismatchException
【发布时间】:2017-08-29 19:11:40
【问题描述】:

我遇到了一些非常奇怪的问题。对于所有最新的 PowerBI nuget-packages 及其最新的依赖项迭代,我得到以下异常:

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

在尝试查看我在 Initialize 上发现的 PowerBIClient 源代码时,它确实尝试将 Iso8601TimeSpanConverter 类型的类添加到 JsonConvert 列表中,请看这里:

/// </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 控制台应用程序。除了这个,一切都很好。

这是问题的截图:

Screenshot of the issue

不久前我发现这个开发人员有类似的问题,但与 PowerBI 无关。然而没有答案。

Adding Iso8601TimeSpanConverter to JsonConverter list throws ArrayTypeMismatch exception

【问题讨论】:

    标签: c# powerbi powerbi-embedded


    【解决方案1】:

    您现在提供的问题的链接包含帮助我解决此问题的提示。就我而言,这是由 GAC 中安装的多个版本的 Newtonsoft.Json.dll 引起的。在我配置我的应用程序以将库引用解析为最新版本后,异常就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多