I am trying to make use of the Microsoft.Extensions.DependencyInjection package in Visual Studio Code, but I’m receiving the "type or namespace could not be found" error. This is a .NET 6 project, and I’ve double checked that the version of the DependencyInjection package I’m using (7.0) is compatible .NET 6 (see here). The only dependency listed on that same page is Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0), which I also have added to the project.
I’ve searched every which way and can’t find any solution that works for me. Here’s what my .csproject file looks like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.10.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0 />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
2
Answers
This problem seems to have been resolved after restarting my computer.
As you can see from the syntax highlighting, you’re missing a
"
in the version attribute of the second PackageReference:Should be:
(Where I abbreviated the include attribute value for brevity).
If that’s somehow not the issue: Did you add a
using
statement?