Unable to upgrade Azure Functions Core Tools, Exception "Cannot create instance of type 'NuGet.Versioning.VersionRange'"
Asked Answered
M

3

5

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:

Adding the verbose flag does not get me any further and outputs the following:

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.

Mudskipper answered 8/9, 2022 at 7:24 Comment(2)
Hi Jon Koeter, glad to know you've found the solution to resolve this issue! Please consider accepting it as an answer to change its status to Answered. It will also help others to solve a similar issue. See can I answer my own question.., Just a reminder :)Chellman
thanks. Delete the folder C:\Users***\AppData\Local\AzureFunctionsTools.Chellman
M
8

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.

Mudskipper answered 8/9, 2022 at 7:31 Comment(0)
P
1

For Linux Users:

This could resolve your issue:

Uninstall:

npm uninstall -g azure-functions-core-tools

ReInstall:

npm install -g azure-functions-core-tools
Padre answered 3/6 at 6:42 Comment(0)
R
-1

This worked for me:

  1. Close Visual Studio,
  2. Delete folder C:\Users\***\AppData\Local\AzureFunctionsTools
  3. Delete temp and %temp%
  4. Restart PC
  5. Restart Visual Studio.
  6. Launch Application, folder gets recreated.

App started running for me and the below error got resolved:

A host error has occurred during startup operation '8bd9dcec-3c37-4ecf-9db9-894534073cfd'.

[2022-11-15T07:08:40.813Z] System.Private.CoreLib: Could not load file or assembly 'Microsoft.Azure.WebJobs.Extensions.Http, Version=3.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

Rainband answered 15/11, 2022 at 10:2 Comment(1)
Yep, that's in my answer. Did you mean to leave a comment?Mudskipper

© 2022 - 2024 — McMap. All rights reserved.