Thursday, October 11, 2018

Xamarin Forms and Web API debugging

I'm new to Xamarin and was trying to get the application running on my local machine. The issues I faced are
  • I was unable to see the error details when an exception is thrown, I did overcome this issue by putting the code in a try catch block. Then I came to know that we can't access the API services hosted in IISExpress (System.Net.WebException: Failed to connect to localhost/127.0.0.1).
  • To access the Web API services in the device you need to make the below changes.  
  • Go to project properties and make the below changes (Change local host to 127.0.0.1)


  • Go to Xamarin and access the API using  http://10.0.2.2:5001 
  • Android Emulator has a special address http://10.0.2.2:your_port that points to 127.0.0.1:your_port on your host machine. 
Once you have done the above steps you now should be able to run the application by setting both Android and API projects as start up projects.