【发布时间】:2026-01-01 13:55:01
【问题描述】:
将图像发送到 Google Api 函数时出现以下错误
//Load the image file into memory
var image = Google.Cloud.Vision.V1.Image.FromStream(uplFile.PostedFile.InputStream);
// Instantiates a client
var client = Google.Cloud.Vision.V1.ImageAnnotatorClient.Create();
// Performs label detection on the image file
var response = client.DetectDocumentText(image);
无法加载文件或程序集“Google.Apis.Auth, Version=1.21.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab' 或其之一 依赖关系。定位程序集的清单定义不 匹配程序集引用。 (HRESULT 异常:0x80131040)
StackTrace:在 Google.Api.Gax.Grpc.ChannelPool.CreateChannelCredentialsUncached 的 System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) 的 Google.Api.Gax.Grpc.ChannelPool.d__5.MoveNext() () 在 System.Threading.Tasks.Task`1.InnerInvoke() 在 System.Threading.Tasks.Task.Execute() --- 从先前抛出异常的位置结束堆栈跟踪--- 在 System.Runtime。 ExceptionServices.ExceptionDispatchInfo.Throw() 在 Google.Api.Gax.TaskExtensions.WaitWithUnwrappedExceptions(Task task) 在 Google.Api.Gax.Grpc.ChannelPool.GetChannel(ServiceEndpoint endpoint) 在 Google.Cloud.Vision.V1.ImageAnnotatorClient.Create( ServiceEndpoint 端点,ImageAnnotatorSettings 设置)在.....
package.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.SqlServer.Types" version="11.0.1" targetFramework="net40" />
<package id="Google.Api.CommonProtos" version="1.1.0" targetFramework="net45" />
<package id="Google.Api.Gax" version="2.2.1" targetFramework="net45" />
<package id="Google.Api.Gax.Grpc" version="2.2.1" targetFramework="net45" />
<package id="Google.Apis" version="1.30.0" targetFramework="net45" />
<package id="Google.Apis.Auth" version="1.30.0" targetFramework="net45" />
<package id="Google.Apis.Core" version="1.30.0" targetFramework="net45" />
<package id="Google.Cloud.Vision.V1" version="1.1.0" targetFramework="net45" />
<package id="Google.Protobuf" version="3.3.0" targetFramework="net45" />
<package id="Grpc.Auth" version="1.7.0" targetFramework="net45" />
<package id="Grpc.Core" version="1.7.1" targetFramework="net45" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net45" developmentDependency="true" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
<package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" />
<package id="System.Net.Http" version="4.3.1" targetFramework="net45" />
</packages>
web.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Google.Apis.Auth" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.34.0.0" newVersion="1.34.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Apis.Auth.PlatformServices" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.34.0.0" newVersion="1.34.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Protobuf" publicKeyToken="a7d26565bac4d604" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.6.0.0" newVersion="3.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Api.CommonProtos" publicKeyToken="3ec5ea7f18953e47" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Api.Gax" publicKeyToken="3ec5ea7f18953e47" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.4.0.0" newVersion="2.4.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Api.Gax.Grpc" publicKeyToken="3ec5ea7f18953e47" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.4.0.0" newVersion="2.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
【问题讨论】:
-
-相同的代码在本地机器上工作
-
-.Net framework 使用的是 4.5
-
请检查部署在IIS上的代码中是否存在Google.Apis.Auth.dll
-
Yes..Google.Apis.Auth.dll 存在于版本 1.30.0 @IpsitGaur
-
但是您的代码要求版本为 1.21.0,如错误所示,本地环境中是否提供相同的版本?
标签: c# google-api google-cloud-platform ocr google-vision