Error connecting to Azure Subscription from VisualStudio

I wanted to make this post with the hope of saving others time. Last two days I have been troubleshooting issue connecting to my Azure Dev/Test subscription. I had developed a custom resource group template and was getting ready to test the template by doing a sample deployment to my azure subscription. Unfortunately I simply could not get past the sign-in in “deploy to resource group” dialog in Visual Studio 2015. Since I had multiple subscriptions on my laptop as most of us do when I pick the Microsoft account from drop down in this case “” I would get the visual studio sign in page where I enter “”, STS would then redirect me to live and I’m able to login there and would come back to the “deploy to resource group” dialog but all the fields remained read only. I had no idea why the fields were still read only. Unfortunately what had happened was my sign-in process had failed (not that I used invalid login or anything), it would have been helpful if VisualStudio had shown some error message to me, additionally there was nothing visually in the dialog that would have given me some indication that there was some problem with sign in, as you can see from the screen shot below.


So I popped back to Visual Studio 2013 and opened the same resource group template project and tried to deploy and here is what I found. In the deploy to resource group dialog looks like below in VS 2013, when I tried to sign in to my azure Dev/Test subscription I basically got the same behavior as VS 2015 but the difference is I could visually see that I was not signed in even though I successfully signed in to live. If the sign in was successful the button text changes to Sign out and all the fields become enabled.


Either way there should be some sort of error message shown to user when there is a problem with sign in. At this point I needed to find out what is really happening so I tried creating a new ASP.NET project in Visual Studio 2015 and selected “Host in the Cloud” Project was successfully created but no cloud resources were provisioned in my azure subscription and there was no error messages as well, VisualStudio 2015 had decided to fail gracefully. I attempted to do the same thing in Visual Studio 2013 and right after click ok in project creation dialog, got the dialog shown below


So I clicked on “Sign In” in the above dialog signed in using my which is associated with my Azure Dev/Test subscription and ended up getting error below from Visual Studio 2013 after the sign in.


At this point I ‘m still not sure exactly what the heck is going on. I can successfully login to both Azure Portal (old and new) using my but Visual Studio was still crapping all over the place. What is up with the error messages VisualStudio? What ever happened to good user experience Smile 

So as a last resort I tried connecting to my Azure Subscription from Server explorer and got following error


Error above got me confused even more, other thing I noticed was in VS 2015 under account settings page it was showing one account for and another one for and both as Microsoft account. That did not make any sense to me. So I switched to PowerShell and ran Get-AzureAccount and surely there was two accounts, see below


What was interesting here was the second user had no subscription associated, it was just associated with a different tenant, keep in mind is not even an organization account, its just my business email hosted in google apps for business. What I noticed is that visual studio was adding this account when I was signing in using my Really bizarre stuff. At this point I knew something was up with my live account, to validate I added another live account to my existing dev/test azure subscription as co administrator and attempted to sign in using this account instead of the and everything worked as expected, this really confirmed my assumption.

I focused my full attention on trying to figure out what could be wrong with account, checked visual studio service settings, Azure AD side, couldn’t really figure out what could be the root cause. As a last resort I started go back like weeks and try to remember all the changes I might have done from my memory any thing that could have potentially caused this. Suddenly it dawned on me, my client had granted access to their office 365 SharePoint site to my business email and once I received the invitation email I clicked on the link and logged into the site using my Now my Microsoft account account is linked to my clients azure ad tenant for office 365 under email. I’m not 100% clear what is happening under the hood after you sign in to azure subscription from visual studio, but my guess is there is multiple bugs in that code per the behavior I’m seeing.

Basically after that point it completely broke the connect to Azure functionality from VisualStudio. I was able to successfully repro this using another live account that was working before. Steps to reproduce this issue are quite straight forward, see below.

  1. Login to an office 365 SharePoint site using administrator account and share site to an external email address, it can be anything, assuming you can check the email.
  2. Once you receive the invite email click on the link in email to access the SharePoint site (Make sure you clear cache and that there are no cookies left from previous logins). This will bring up a realm selection page where you will see two options Microsoft account and Organization account. Depending on how you login to your azure subscription, if you use a Microsoft account then you choose Microsoft account otherwise you’ll select Organization account and login.
  3. After you are successfully logged in, open VisualStudio, (2013 or 2015) and try to connect to azure subscription using the same account that you used to login to Office 365 SharePoint site. You can try connecting via server explorer, create a project and select host in cloud option, deploy resource group etc. nothing will work.

Once I removed the account from Azure AD tenant for Office 365 SharePoint site, everything will start working again. Hopefully this saves some time for others, been pulling my hair on this for last two days.