Remote debugging Azure Mobile Service - Object reference not set to an instance of an object

Quick note: Below case only affects developers using VS2015 (only) and AzureSDK for .NET - v2.8.2 seems to fix the problem.

Link: Azure SDK for .NET v2.8.2

Many of you are using Azure Mobile Service as your service back-end for the mobile device applications. It has been there for a while now and it is pretty awesome.

Azure and Microsoft recently shifting towards the concepts of App Mobile Service resource to do the Mobile Service stuffs with the same pattern that applies to ASP.NET MVC and WebAPI.

Flash back

For everyone who has a hosted Azure Mobile Service in their Azure Account should be seeing this new option called "Migrate to App Service" when that resource is selected in Classic Azure Portal:

This is an in-place upgrade to the App Service provided by Azure team. When you click on that option you see details of the migration, what you gain and how the billing works.

Write down the Mobile Service resource name and click on confirm and the migration will initiate and complete in few minutes.

Once the migration is complete, you won't be able to see the Mobile Service in Classic portal anymore. The resource type gets changed to "App Service" and now visible in new Azure portal (https://portal.azure.com)

The Problem

For some reasons, you might want to be able to remote debug the mobile service or App Mobile Service, may your cat said so... or you want to live debug an issue... or your service is not working as expected after deploy but mostly because your cat said so :D

After you have migrated your Azure Mobile Service to the App Service resource, when you try to remote debug from your Visual studio > Server Explorer > Azure > App Service > [App Service Plan Name] > [Resource Name] > Right click - "Attach Debugger".

You will observe that few seconds later a error pops up saying -

"Object reference not set to an instance of an object"

The Solution

There is something going wrong when Visual Studio tries to attach debugger here and this issue does not happen if you try to attach debugger to a web application or any mobile service created in the App Service resource type (which has not gone through the migration)

Here is the way to overcome the problem and remote debug your migrated mobile service code.

Step 1: In Visual Studio, click on Debug (Top Menu) > "Attach to Process..."

Step 2: This shows the "Attach To Process" dialog. In the input labeled as "Qualifier" - type in the full app mobile service name. In my case the resource name is "demo-ms" so the full app mobile service name would be - "demo-ms.azure-mobile.net". Then hit - "Refresh"

Step 3: On hitting refresh (first time only) - A new dialog will appear which ask for credentials to access the remote azure resource. The username and password can be obtains from the publish profile of your resource.

Download the publish profile settings file, in there node - publishData > publishProfile > Attribute values userName & userPWD are to be used for the username and password in the popped dialog.
Note: Remember to prefix .\ in front of the username.

Step 4: On accepting credentials you will be seeing list of remote process in "Available Processes" list.

Click on the "w3wp.exe" process from the list and click "Attach".

Done: After few seconds - few minutes your code will go into running mode in Visual Studio and the debugger will be attached successfully. At this point you can start debugging your App Mobile Service without any issue.

Thanks to Matt and Ling from Azure and Product team to quickly help (team at AgriSync) figure it out.

Similar post from team @ Microsoft. Thanks to Amit (From Microsoft Azure Support) for sharing it out.

Happy Coding!