skip to Main Content

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


  1. Chosen as BEST ANSWER

    This problem seems to have been resolved after restarting my computer.


  2. As you can see from the syntax highlighting, you’re missing a " in the version attribute of the second PackageReference:

    <PackageReference Include="...DependencyInjection" Version="7.0.0 />
    

    Should be:

    <PackageReference Include="...DependencyInjection" Version="7.0.0" />
    

    (Where I abbreviated the include attribute value for brevity).

    If that’s somehow not the issue: Did you add a using statement?

    using Microsoft.Extensions.DependencyInjection;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search