无法加载文件或程序集System.Xml.XPath - .Net 4.6.2引用了.Net Standard 1.3。

4
我正在使用VS2017、C#和.NET Framework 4.6.2开发应用程序。
我有一个类库,为其安装了Geocoding Core和Google nuget包。这些是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.

1
最好发布英文版的错误信息,这样会更容易引起关注。 - Saleem
@Saleem 完成了! :) - Ludovic C
已测试通过 .net framework 4.6.2 和 .net core 2.0 控制台项目。运行良好,无错误。 - Saleem
你解决了吗?我在Azure上使用4.6.2版本的地理编码器也遇到了类似的问题。 - sheamus
1个回答

0
如果这是一个Asp.Net项目,请在Web项目中安装System.Xml.Xpath nuget包。我遇到了这个问题,因为我已经将Geocoding库安装到了我的Service项目(与我的API控制器分开的项目)。我不得不手动安装Xpath nuget到Web项目中,这解决了问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接