【问题标题】:Azure function uses incorrect DLL versionAzure 函数使用了不正确的 DLL 版本
【发布时间】:2019-09-13 05:02:46
【问题描述】:

我创建了一个 Azure 函数,该函数通过 Dynamics 365 中的 webhook 调用。读取远程上下文对象的简单方案确实有效;但是,更复杂的场景会引发错误。尝试使用 CrmServiceClient (Microsoft.Xrm.Tooling.Connector) 获取 Dynamics 服务对象的实例,但是当此行运行 CrmServiceClient client = new CrmServiceClient(crmConnectionString) 时会引发错误:

“无法从程序集 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 中加载类型 'Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior'” em>

我检查了 Azure 中 bin 目录中的 DLL,Microsoft.IdentityModel.Clients.ActiveDirectory 的版本是 2.22。

另外,我检查了 Azure 中的 xxx.deps.json 文件,它显示的版本相同:

"Microsoft.IdentityModel.Clients.ActiveDirectory/2.22.0.0": {
        "runtime": {
          "Microsoft.IdentityModel.Clients.ActiveDirectory.dll": {
            "assemblyVersion": "2.22.0.0",
            "fileVersion": "2.22.30211.1727"
          }
        }

我已经为提到的 DLL 搜索了 3.14.2.11 版本,但找不到它。所以我想知道为什么 Azure 会加载那个版本?

根据其他一些帖子的建议,我在我的函数文件夹下添加了一个文件 -function.proj- 以降级 Azure 加载的那个 DLL 的版本,这是内容:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="2.22.0" />
</ItemGroup>
</Project>

不幸的是,它并没有改变结果。有没有人遇到过同样的问题?

【问题讨论】:

    标签: c# azure-functions webhooks dynamics-365


    【解决方案1】:

    Microsoft.Xrm.Tooling.Connector 依赖于.net framework 4.6.2,而你的天蓝色函数TargetFramework 是netstandard 2.0。因此,请确保您的函数的运行时版本。

    然后将Microsoft.IndentityModel.Client.ActiveDirectory升级到2.28.3版本

    如果您的函数运行时为 ~1,请使用以下内容创建 project.json

    {
      "frameworks": {
        "net46":{
          "dependencies": {
            "Microsoft.IdentityModel.Clients.ActiveDirectory": "2.28.3"
          }
        }
    } 
    

    如果您的函数运行时为 ~2,请按如下方式创建 function.proj。

    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>netstandard2.0</TargetFramework>
        </PropertyGroup>
        <ItemGroup>
            <PackageReference Include="Microsoft.IndentityModel.Client.ActiveDirectory" Version="2.28.3"/>
        </ItemGroup>
    </Project>
    

    【讨论】:

    • 该函数的运行时间是 2。我们已经有一个 function.proj,如帖子中所述。我们指的是在其他环境中工作的正确版本(2.22.0)。顺便说一句,2.28.3 版适用于 Windows phone。
    【解决方案2】:

    只需将运行时降级到版本 1 就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多