Could not load file or assembly “System.Net.Http.W

2019-08-05 05:13发布

问题:

I recently revived a project in Mono we haven't used in a while. One of the first things I did was upgrade our shared code, which contained the AWSSDK for .NET nuget package (on version 2.0.11). Our version of the Nuget package was also updated.

However now on the target machine I'm seeing the code throw an exception trying to resolve System.Net.Http.Webrequest, which should exist and be supported in Mono. I even tried pulling the AWSSDK code from Git and building in Xamarin, and it builds fine, but at runtime my code fails to resolve the dependency inside the AWS SDK call.

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
  at Amazon.Runtime.AmazonWebServiceClient.Initialize () [0x00000] in <filename unknown>:0 
  at Amazon.Runtime.AbstractWebServiceClient..ctor (Amazon.Runtime.AWSCredentials credentials, Amazon.Runtime.ClientConfig config, AuthenticationTypes authenticationType) [0x00000] in <filename unknown>:0 
  at Amazon.Runtime.AmazonWebServiceClient..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.Runtime.ClientConfig config, AuthenticationTypes authenticationType) [0x00000] in <filename unknown>:0 
  at Amazon.S3.AmazonS3Client..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.S3.AmazonS3Config clientConfig) [0x00000] in <filename unknown>:0 
  at Core.Amazon.S3.S3File..ctor () [0x00000] in <filename unknown>:0 
  at LitmusMono.WebmailMonoTestingService..ctor () [0x00000] in <filename unknown>:0 
  at LitmusMono.ServiceStarter.InitTestingServices () [0x00000] in <filename unknown>:0 
Could not load file or assembly 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

  at Amazon.Runtime.AmazonWebServiceClient.Initialize () [0x00000] in <filename unknown>:0 
  at Amazon.Runtime.AbstractWebServiceClient..ctor (Amazon.Runtime.AWSCredentials credentials, Amazon.Runtime.ClientConfig config, AuthenticationTypes authenticationType) [0x00000] in <filename unknown>:0 
  at Amazon.Runtime.AmazonWebServiceClient..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.Runtime.ClientConfig config, AuthenticationTypes authenticationType) [0x00000] in <filename unknown>:0 
  at Amazon.S3.AmazonS3Client..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.S3.AmazonS3Config clientConfig) [0x00000] in <filename unknown>:0 

Some notes: The release configuration I'm using is forcing x86 build because one of my child projects is x86.

The target platform for the program to run is OSX with Mono 3.0.4 beta.

回答1:

I had a similar error but it was "System.Net.Http.Primitives": To fix it I rolled back the AWSSDK version until it worked, in my case 3.1.10. This can be done using the NuGet Package Manager in Visual Studio Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution, then select "Installed" and then the package. Change the version number on the right hand side then click install. Hope this helps!!!