4

我正在使用 VS2017 开发应用程序C#.Net Framework 4.6.2.

我有一个类库,我为它安装了Geocoding CoreGooglenuget 包。那些是Net Standard 1.3图书馆。

这增加了对其他几个库的依赖,以及System.Xml.XPath.

虽然,在运行时,当我尝试访问其中一种Geocoding.net方法时

var geocoder = new GoogleGeocoder("key");

var task = geocoder.GeocodeAsync(searchString);

task.Wait()

我收到这个错误

System.AggregateException occurred
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Easymage.TEC.Entities.Application.QueryHandlers.AddressSearchQueryHandler.Handle(AddressSearchQuery query) in C:\Users\Ludovic\Source\Repos\Easymage.TEC\Easymage.TEC.Entities.Application\QueryHandlers\AddressSearchQueryHandler.cs:line 32

Inner Exception 1:
GoogleGeocodingException: There was an error processing the geocoding request. See Status or InnerException for more information.

Inner Exception 2:
FileLoadException: Could not load file or assembly 'System.Xml.XPath, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Inner Exception 3:
FileLoadException: Could not load file or assembly 'System.Xml.XPath, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我不知道该怎么做。System.XML.XPath 文件位于输出文件夹中。

我尝试添加程序集绑定重定向:

  <dependentAssembly>
    <assemblyIdentity name="System.Xml.XPath" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
  </dependentAssembly>

和这个

  <dependentAssembly>
    <assemblyIdentity name="System.Xml.XPath" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.1.0" />
  </dependentAssembly>

似乎没有任何效果。我总是收到这个错误。

这是带有绑定重定向的融合日志:

=== Pre-bind state information ===
LOG: DisplayName = System.Xml.XPath, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Ludovic/Source/Repos/Easymage.TEC/bin/Server/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Geocoding.Google, Version=4.0.0.0, Culture=neutral, PublicKeyToken=48f410544ef36ab4.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Ludovic\Source\Repos\Easymage.TEC\bin\Server\Debug\Easymage.TEC.ServiceHost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.1.0 redirected to 4.0.2.0.
LOG: Post-policy reference: System.Xml.XPath, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80131040.

这是没有绑定重定向的融合日志:

=== Pre-bind state information ===
LOG: DisplayName = System.Xml.XPath, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Ludovic/Source/Repos/Easymage.TEC/bin/Server/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Geocoding.Google, Version=4.0.0.0, Culture=neutral, PublicKeyToken=48f410544ef36ab4.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Ludovic\Source\Repos\Easymage.TEC\bin\Server\Debug\Easymage.TEC.ServiceHost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Xml.XPath, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Users/Ludovic/Source/Repos/Easymage.TEC/bin/Server/Debug/System.Xml.XPath.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
4

1 回答 1

0

如果这是一个 Asp.Net 项目,请将 System.Xml.Xpath nuget 包安装到 Web 项目。我遇到了这个问题,因为我将地理编码库安装到了我的服务项目(与我的 API 控制器分开的项目)。我不得不手动将 Xpath nuget 安装到 web 项目中,它解决了它。

于 2018-02-11T22:33:21.990 回答