Azure Functions assembly conflicts when I'm using Google.Protobuf

1

I'm new in Azure Functions and I'm creating a FirestoreDb connection. But when I call the FirestoreDb.Create method, I take this exception:

Exception while executing function: OutputFirebase. Output.Firebase.Services.Functions: Could not load file or assembly 'Google.Protobuf, Version=3.5.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Google.Protobuf, Version=3.5.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604'.

In the AppDomain.CurrentDomain.GetAssemblies() I see the version 3.0.0

Google.Protobuf version 3.0.0 image:

Google.Protobuf version 3.0.0 image

But I installed the version 3.5.1 into *.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# Code Sample

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;
            }
        }
    }
}

Any help on why this is happening or how to get around it?

Visual Studio 2017 - Version 15.6.2

c#
function
firebase
.net-assembly
azure-functions

1 Answer

4

Protobuf 3.3.0 is used by Azure Functions Host for communication with out-of-proc Functions (e.g. written in java).

So, if you control your references, I would recommend switching the protobuf version to be the same as the runtime one.

If you can't control the version, you might actually be blocked, since there is no binding redirect support, especially for v2 / .NET Standard. Be sure to mention your scenario in github issue.

answered on Stack Overflow Mar 16, 2018 by Mikhail Shilkov

User contributions licensed under CC BY-SA 3.0