我是Azure功能的新手,我正在创建FirestoreDb连接。但是当我调用FirestoreDb.Create
方法时,我采用了这个例外:
执行函数时出现异常:OutputFirebase。 Output.Firebase.Services.Functions:无法加载文件或程序集' Google.Protobuf,Version = 3.5.1.0,Culture = neutral,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
答案 0 :(得分:3)
因此,如果您控制引用,我建议将protobuf版本切换为与运行时版本相同。
如果无法控制版本,实际上可能会被阻止,因为没有绑定重定向支持,尤其是对于v2 / .NET Standard。请务必在github issue中提及您的方案。