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:

    SSL Error - The connection for this site is not secure

     After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...