在IIS上托管时使用Google Vision OCR API时出现问题

时间:2018-06-28 03:48:16

标签: c# google-api google-cloud-platform ocr google-vision

在将图像发送到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,版本= 1.21.0.0,   文化=中性,PublicKeyToken = 4b01fa6e34db77ab'或其中之一   依赖性。找到的程序集的清单定义不   匹配程序集参考。 (来自HRESULT的异常:0x80131040)

StackTrace:在System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start [TStateMachine](TStateMachine&stateMachine)在Google.Api.Gax.Grpc.ChannelPool.CreateChannelCredentialsUncache中位于Google.Api.Gax.Grpc.ChannelPool.d__5.MoveNext() ()在System.Threading.Tasks.Task`1.InnerInvoke()在System.Threading.Tasks.Task.Execute()-从上一个引发异常的位置开始的堆栈跟踪-在System.Runtime Google.Api.Gax.TaskExtensions.WaitWithUnwrappedExceptions(任务任务)的ExceptionServices.ExceptionDispatchInfo.Throw()Google.Cloud.Vision.V1.ImageAnnotatorClient.Create的Google.Api.Gax.Grpc.ChannelPool.GetChannel(ServiceEndpoint端点) 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>

1 个答案:

答案 0 :(得分:1)

首先,我将检查您的项目文件在哪里寻找DLL。您可以通过在Visual Studio中展开依赖关系,右键单击Google.Apis.Auth依赖关系并选择属性来找到此内容。我的猜测是,它指向DLL的另一个副本,位于您计算机上其他未发布的位置。如果是这种情况,则可以通过NuGet重新安装来解决问题(它将更新项目文件中的依赖项引用)。我将通过NuGet卸载该软件包,确保已从依赖项列表中将其删除,然后重新安装。

第二,尝试将<bindingRedirect oldVersion="0.0.0.0-1.30.0" newVersion="1.30.0" />依赖项的<dependentAssembly>标签内的Google.Apis.Auth添加到您的web.config文件中。这告诉应用程序您正在使用比项目实际需要的新版本来满足依赖性。该部分应如下所示。请参见herebindingRedirect的文档。

<dependentAssembly>
    <assemblyIdentity name="Google.Apis.Auth" publicKeyToken="xxx" cultuer="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.30.0" newVersion="1.30.0" />
</dependentAssembly>