来自 Microsoft.PowerPlatform.Dataverse.Client 的 System.InvalidCastException

问题描述 投票:0回答:1

3 天前,我们开始在生产中的 Azure Function 应用程序中间歇性地遇到

System.InvalidCastException
异常,并且无法在预生产或本地重现该问题。

Exception while executing function: GetQueue Error constructing handler for request of type MediatR.IRequestHandler`2[Function Name space,System.Boolean]. Register your handlers with the container. See the samples in GitHub for examples. Failed to connect to Dataverse Unable to cast object of type 'generatedProxy_2' to type 'Microsoft.PowerPlatform.Dataverse.Client.IOrganizationServiceAsync'. 

重新启动 Azure 函数应用程序后,它会再次开始工作。

看起来这个问题与 nuget 包有关

Microsoft.PowerPlatform.Dataverse.Client

查看打击将其待办事项与扩展联系起来。

无法将类型“ generatedProxy_2”的对象转换为类型“ Microsoft.PowerPlatform.Dataverse.Client.IOrganizationServiceAsync”

无法连接到 Dataverse:无法将“ generatedProxy_3”类型的对象转换为“Microsoft.PowerPlatform.Dataverse.Client.IOrganizationServiceAsync”类型

Microsoft.PowerPlatform.Dataverse.Client
从 1.0.9 升级到 1.1.32 后,问题仍然存在。

函数应用运行时版本:~4

.net版本6.0

我们的启动代码如下所示

services.AddSingleton<IOrganizationServiceAsync, ServiceClient>(provider =>
{
        return GetService(d365Settings);
});
public static ServiceClient GetService(D365Settings d365Settings)
{
    var client = new ServiceClient(new Uri(d365Settings.OrganizationUri), d365Settings.ClientId, d365Settings.ClientSecret, false);

    if (client.IsReady)
        return client;

    throw new ArgumentException($"Unable to connect to CE, Error: {client.LastError}", client.LastException);
}

csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
    <PackageReference Include="Microsoft.PowerPlatform.Dataverse.Client" Version="1.1.32" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\Core\Project1.csproj" />
    <ProjectReference Include="..\..\Core\Project2.csproj" />
  </ItemGroup>

</Project>
c# azure-functions dataverse
1个回答
0
投票

您的异常位于 MediatR.IRequestHandler 处。看起来您使用了 MediatR 包,请检查 MediatR 正常工作所需的初始化代码。

© www.soinside.com 2019 - 2024. All rights reserved.