【问题标题】:Azure Functions assembly conflicts when I'm using Google.Protobuf使用 Google.Protobuf 时 Azure Functions 程序集冲突
【发布时间】:2018-03-16 04:05:47
【问题描述】:

我是 Azure Functions 的新手,我正在创建 FirestoreDb 连接。但是当我调用FirestoreDb.Create 方法时,我接受了这个例外:

执行函数时出现异常:OutputFirebase。 Output.Firebase.Services.Functions:无法加载文件或程序集“Google.Protobuf,版本=3.5.1.0,文化=中性,PublicKeyToken=a7d26565bac4d604”。无法找到或加载特定文件。 (来自 HRESULT 的异常:0x80131621)。 System.Private.CoreLib:无法加载文件或程序集“Google.Protobuf, Version=3.5.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604”。

AppDomain.CurrentDomain.GetAssemblies() 我看到version 3.0.0

Google.Protobuf 版本 3.0.0 映像:

但我将version 3.5.1 安装到*.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    <AssemblyName>Output.Firebase.Services.Functions</AssemblyName>
    <RootNamespace>Output.Firebase.Services.Functions</RootNamespace>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Google.Cloud.Firestore" Version="1.0.0-beta02" />
    <PackageReference Include="Google.Protobuf" Version="3.5.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.9" />
  </ItemGroup>
  <ItemGroup>
    <None Update="firestore-key.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

C# 代码示例

using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Google.Cloud.Firestore;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

namespace Output.Firebase.Services.Functions
{
    public static class OutputFirebaseFunction
    {
        private static FirestoreDb FirestoreDb;

        [FunctionName("OutputFirebase")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "output/firebase")]HttpRequestMessage req, TraceWriter log, ExecutionContext executionContext)
        {
            log.Info("C# HTTP trigger function processed a request.");

            await InitializeDatabaseAsync(Directory.GetParent(executionContext.FunctionDirectory).FullName);
            return req.CreateResponse(HttpStatusCode.OK);
        }

        private static async Task InitializeDatabaseAsync(string path1)
        {
            try
            {
                var test = Google.Protobuf.FieldCodec.ForBool(13);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}

关于为什么会发生这种情况或如何解决它的任何帮助?

Visual Studio 2017 - 版本 15.6.2

【问题讨论】:

  • 函数 V1 不使用协议缓冲区,因此作为临时解决方法,您是否尝试过使用 V1,因为应该没有冲突?

标签: c# function firebase .net-assembly azure-functions


【解决方案1】:

Protobuf 3.3.0 is used 由 Azure Functions Host 提供,用于与进程外函数(例如用 java 编写)进行通信。

因此,如果您控制引用,我建议将 protobuf 版本切换为与运行时版本相同。

如果您无法控制版本,您实际上可能会被阻止,因为没有绑定重定向支持,尤其是对于 v2 / .NET Standard。请务必在github issue 中提及您的方案。

【讨论】:

  • switching the protobuf version to be the same as the runtime one 你是怎么做到的?
  • @Milo &lt;PackageReference Include="Google.Protobuf" Version="3.3.0" /&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-20
  • 1970-01-01
  • 1970-01-01
  • 2013-07-05
  • 1970-01-01
  • 2021-11-05
  • 1970-01-01
相关资源
最近更新 更多