Home > database >  Azure function in VSCode gives reference errors
Azure function in VSCode gives reference errors

Time:11-25

I have set up a local Azure Function project in VSCode as per the instructions here enter image description here

Edit: The exact message I get when I mouseover one of the reference errors is The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13 ...

CodePudding user response:

I tried to reproduce the issue:

  1. Firstly, I have selected my workspace folder from the VSCode, enter image description here

  2. Created the function project using func init command in the VS Code terminal. enter image description here

  3. Create the function using func new command in the terminal, selected Http Trigger from the dropdown display of triggers and given the function name as Hello.

enter image description here

  1. Click on the Hello.cs file, then you will get a side dialog box on the bottom of the same VS Code window.

enter image description here

Click on Restore.

OR

enter image description here

If you get two dialog boxes, then click on Restore and Yes so that it will restore the NuGet packages and functions dependencies required for that environment. You can also see in the output terminal opens immediately after clicking restore option: enter image description here

After adding those, you will get clean error-free UI like below:

enter image description here

Note:

  1. If you have written the class/function manually in the code, please check that you renamed the Function class name both in the code as well in the file explorer like:

enter image description here

Updated Answer:

As per your edits and comments, I also installed .Net SDK Version 6 and checked the project in VS Code and I got the restore dialog box again with that red squiggly lines. After clicking on restore option, all red squiggly lines went out and this is the Proof-Of-Concept:

enter image description here

CodePudding user response:

I did get this resolved, though I am not sure exactly how/ why, so i'll just post what I did in case it helps someone else.

Firstly I removed the Microsoft C# extension and re-installed it. I dont think this had any effect and it didnt seem to fix the issue, I am just mentioning it as I will mention everything I did.

When I googled the error that is in my Edit above The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13 I found some references to the MS Build tool/ library shipped with Visual Studio (not VS Code) in regards to .NET 6 and how the .NET 6 requires a certain version of the Build utility.

The recommendation was to upgrade Visual Studio (not VSCode), which I already had installed and that would update the MS Build.

I didnt really understand quite a bit of what I read, but I updated my install of Visual Studio Community 2019 in the hope that it would update MS Build and it seems to have worked.

I expect there is another way to do this without Visual Studio, but I chose this way as I had it installed anyway.

One last thing was I went to bed and had a sleep, then checked it again in the morning.

Cant really say for sure which of the three things worked :)

  • Related