Sunday, August 16, 2020

Async multipart image upload: method not found error

In a strange issue, we would get an error while trying to upload an image using multipart async methods in web api.

  • ExceptionMessage: "Method not found: 'System.Collections.ObjectModel.Collection`1<System.Net.Http.HttpContent> System.Net.Http.MultipartStreamProvider.get_Contents()'."
  • ExceptionType: "System.MissingMethodException"
  • Message: "An error has occurred."
  • Finally we found out that the problem was with System.Net.Http.dll versions not working correctly, the problem and solutions are mentioned at 

    https://stackoverflow.com/questions/54205285/why-im-getting-a-method-not-found-exception-into-production-iis-but-not-in-my-vs

    It was resolved after we added this entry to web.config file

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

    No comments:

    c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

     If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...