Home > OS >  Unable to upgrade Azure Functions Core Tools, Exception "Cannot create instance of type 'N
Unable to upgrade Azure Functions Core Tools, Exception "Cannot create instance of type 'N

Time:09-19

I'm trying to run an Azure Function. After upgrading to .Net 6, debugging it locally with an updated version of Visual Studio 2022 gives me the following exception:

A host error has occurred during startup operation 'dca54039-23ee-4ec2-ad9d-9deafe1b2869'. [2022-09-08T07:07:05.464Z] Microsoft.Extensions.Configuration.Binder: Cannot create instance of type 'NuGet.Versioning.VersionRange' because it is missing a public parameterless constructor.

Exception when running on my machine

My co-workers do not get this error and it works great in production. The big difference we found was that they have a Core Tools Version that differs from mine.

  • Mine: 4.0.3971
  • Theirs: 4.0.4736

I believe the problem lies here, but besides trying to upgrade I also tried other things:

  • Change to <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  • Update all nuget packages for .Net 6.
  • Install latest version of Core Tool as mentioned on this page: Verbose enabled

    Since then I've been trying to upgrade the Tools version. But here's the thing: even though func --version tells me I have 4.0.4736, the debug window still says 4.0.3971. I tried the following things:

    • I uninstalled everything and then installed the MSI again from the page mentioned above.
    • I ran npm i -g azure-functions-core-tools@4 in the Package Manager Console.
    • I uninstalled and re-installed using Chocolatey
    • I re-installed Visual Studio
    • I did the following things in an elevated powershell window:

    PS C:\Windows\system32> npm i -g azure-functions-core-tools@4 --unsafe-perm true

    changed 51 packages, and audited 52 packages in 18s found 0 vulnerabilities

    PS C:\Windows\system32> npm i -g [email protected] --unsafe-perm true

    changed 51 packages, and audited 52 packages in 26s found 0 vulnerabilities

    PS C:\Windows\system32> func --version 4.0.4736

    Nothing seems to help.

    CodePudding user response:

    The solution was:

    • Close Visual Studio
    • Delete folder C:\Users\***\AppData\Local\AzureFunctionsTools
    • Restart Visual Studio.
    • Launch Application, folder gets recreated.

    As soon as I had my co-worker review this question (to make sure I didn't post any vulnerabilities) he said "Oh, that other co-worker found a solution, you should delete C:\Users\***\AppData\Local\AzureFunctionsTools and you're good to go"

    So I did.

    And it works right away.

  • Related