2

I have set up a local Azure Function project in VSCode as per the instructions here https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-csharp?tabs=in-process

The default templated function that is created works when I run it in VSCode, but I am seeing reference errors in the VSCode editor as per screen shot.

When I go to the definition of the HttpRequest class for example, I see no Query method.

How can I fix these?

The options I selected were C#, .NET 6, HTTP Trigger, Anonymous, Add to Workspace

I have installed .NET 6 SDK, Azure Function Tools, C# extension, Azure function extension.

Thank you

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 ...

3 Answers 3

2

I ran into the same problem today. I have the C# extension installed in VS Code and noticed this line in the extension description:

C# Extension description. Advice for using .NET 6

When I set that flag to true (and restarted OmniSharp or VSCode), the issue went away :)

OmniSharp 'useModern' setting

Sign up to request clarification or add additional context in comments.

Comments

0

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

7 Comments

thanks for this detailed explanation. I retried the creating the project exactly as you described ( previously I used the Azure functions sidebar in VSCode). Everything appeared exactly as you show except at the point I get the Restore button almost the entire screen is filled with red underlines and after I click restore (I only got the single Restore dialog) I am left with what is shown in my original screen shot.
After clicking on Restore, you should get rid out of this red squiggly lines. Please check the every step once.
Based on creation way of azure functions in VS Code, you will get either only restore nuget packages dialog box or both c# extension generator and restore dialog box? But if you clicked on restore on the dialog box, it should remove the red squiggly lines by installing the packages, references and dependencies into that project.
Clicking Restore did resolve many of the issues, as I said, there were may more before I clicked Restore. But that happened both the first time I created the project and more recently when I followed your instructions
Did you installed the Azure Functions core tools latest version?
|
0

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 :)

1 Comment

Have you tried in the VS Code without the Visual Studio Installation? It will work in VS Code but it need few prerequisites like Azure Functions Extension, Azure Functions core tools, C# extension, Language specific Installations like .Net Core, Python, Node Js frameworks etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.