I was having this same problem. Reinstalling SDKs didn't seem to be helping and reinstalling Visual Studio sounded too painful so I decided to figure out what was causing the error.
I used another instance of Visual Studio and attached it to debug the offending Visual Studio instance. I couldn't see where the exact error was happening, but I was able to see what library the exception occured in and could see the source code using .NET Reflector to get an idea of what it does.
On startup the Microsoft.Cct.CctSharedPackage library iterates through all the Azure SDKs to figure out which ones are installed on your computer.
I ended up writing a console application to emulate what the startup does and see if I could find what was wrong. All the classes are internal so I had to use reflection to access them.
On my computer it turned out to be the Azure SDK 1.6 that was messed up. The SDK was installed, but the TargetAzureLibraries property was coming back as null. I uninstalled that SDK and it corrected the problem.
Console app below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WindowWidth = 240;
// The Microsft.Cct.AssemblyResolver does this:
/*
private IEnumerable<IAzureToolsVersionInfo> GetInstalledSDKsByProductVersionDesc(IServiceProvider serviceProvider) =>
(from knownProduct in AzureToolsVersionInfoUtilities.GetAllProducts()
where knownProduct.TargetAzureSDK.IsSDKInstalled() && knownProduct.TargetAzureLibraries.IsLibrariesInstalled()
orderby knownProduct.ProductVersion descending
select knownProduct)
*/
// Duplicate this logic using reflection to find the SDK install that is broken.
var asm = System.Reflection.Assembly.LoadFile("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Windows Azure Tools\\Microsoft.VisualStudio.WindowsAzure.Common.2.8.dll");
var typ = asm.GetType("Microsoft.Cct.ProductVersionInfo.AzureToolsVersionInfoConstants");
//Console.WriteLine(typ.ToString());
var allMethods = typ.GetFields(BindingFlags.Static | BindingFlags.Public).Select(it => it.Name).ToArray();
allMethods = allMethods.Where(it => it.StartsWith("WAT") && it.Length == 5).OrderBy(it => it).ToArray();
foreach (string version in allMethods)
{
var fld = typ.GetField(version, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
dynamic val = fld.GetValue(null);
var azTypeInfo = asm.GetType("Microsoft.Cct.ProductVersionInfo.AzureToolsVersionInfo");
bool isSdkInstalled = false;
bool isLibrariesInstalled = false;
Dictionary<string, string> sdkProperties = new Dictionary<string, string>();
Dictionary<string, string> libProperties = new Dictionary<string, string>();
// Get the SDK reference
var targetAzureSDK = azTypeInfo.GetProperty("TargetAzureSDK").GetValue(val);
Type targetAzureSDKProp = targetAzureSDK.GetType();
var methodNames = targetAzureSDKProp.GetMethods().Select(it => it.Name).ToArray();
var sdkIsInstalledMethod = targetAzureSDKProp.GetMethods().FirstOrDefault(it => it.Name == "IsSDKInstalled");
isSdkInstalled = (bool)sdkIsInstalledMethod.Invoke(targetAzureSDK, null);
var sdkProps = targetAzureSDKProp.GetProperties().ToArray();
foreach (var prop in sdkProps)
{
try
{
sdkProperties[prop.Name] = string.Concat(prop.GetValue(targetAzureSDK));
}
catch (Exception ex)
{
sdkProperties[prop.Name] = "Error:" + ex.Message;
}
}
if (isSdkInstalled)
{
// Get the Azure libraries reference
var targetAzureLibraries = azTypeInfo.GetProperty("TargetAzureLibraries").GetValue(val);
Type targetAzureLibrariesProp = targetAzureLibraries.GetType();
var isInstalledMethod = targetAzureLibrariesProp.GetMethods().FirstOrDefault(it => it.Name == "IsLibrariesInstalled");
isLibrariesInstalled = (bool)isInstalledMethod.Invoke(targetAzureLibraries, null);
var props = targetAzureLibrariesProp.GetProperties().ToArray();
foreach (var prop in props)
{
try
{
libProperties[prop.Name] = string.Concat(prop.GetValue(targetAzureLibraries));
}
catch (Exception ex)
{
libProperties[prop.Name] = "Error:" + ex.Message;
}
}
}
// Output details of this SDK
Console.WriteLine("{0}, {1}, {2}", version, isSdkInstalled, isLibrariesInstalled);
Console.WriteLine("\tSDK");
foreach (var kp in sdkProperties)
{
Console.WriteLine("\t{0} {1}", kp.Key, kp.Value);
}
Console.WriteLine("\tLib");
foreach (var kp in libProperties)
{
Console.WriteLine("\t{0} {1}", kp.Key, kp.Value);
}
}
}
}
}