How to correct Null Reference Exception when using HttpClient with Xamarin and iOS


When I use HttpClient in my Xamarin project it works with Android but throws a Null Reference exception on iOS.


Add an app.config with the the following content:

<?xml version="1.0" encoding="utf-8"?>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="" newVersion="" />



The namespace for HttpClient exists on Android and iOS which conflicts with the one in System.Net.HttpClient. The redirect makes sure you find the correct version.

Add comment