Joshcarlisle.io is a blog written by Josh Carlisle based out of Raleigh North Carolina where I explore, Share, and sometimes abuse the modern software development landscape. 

 

Are you getting "KeyNotFoundException: The given key was not present in the dictionary." with your VSTS Builds?

Are you getting "KeyNotFoundException: The given key was not present in the dictionary." with your VSTS Builds?

TLDR; 
Asp.Net Core 1.1 applications may break after installing the .Net Core 2.1 SDK.  The .net Core 2.1 SDK is installed on the VSTS managed build servers which may cause your asp.net core 1.1 applications built on VSTS to fail at run-time on startup generating a "KeyNotFoundException" exception. To resolve this without having to make any code changes add a .net core tool installer task in your build to use the SDK 1.1.7. This will ensure the 2.1 SDK will not impact your build. This applies to .net framework asp.net core 1.1 projects as well. 


Very recently several Asp.Net Core 1.1 projects that have been humming along nicely for a year in our VSTS Build and Release pipeline began to fail at run-time a few days ago. There were no code changes but the common factor was any build coming from VSTS would generate runtime errors while locally published builds (in our case to Azure) were successful.  We were receiving a "KeyNotFoundException: The given key was not present in the dictionary." during startup in our application. 

21sdkerror.png


Some quick searches found that we were not alone in problems with builds coming from VSTS. https://github.com/aspnet/Home/issues/3132#issuecomment-394620467 . It would appear that the .Net Core 2.1 SDK was the culprit. We confirmed that the 2.1 SDK was being used on our managed build server. It all likely started when Microsoft updated the SDK on their managed build servers. To resolve the issue some were able to make code changes to their 1.1 projects but in the end the easiest solution for our VSTS build was to use the .Net Core Tool Installer to ensure the build was only using 1.1.7 of the .Net Core SDK (or whatever your desired version is).  

AzureADBug-Fix.png

If you're running into this local consider updating your global.json file in the project to specify which version of the SDK to use.

Hopefully this saves some folks a few headaches!

Introducing Azure Function Extensions for Cognitive Services

Introducing Azure Function Extensions for Cognitive Services