OpenAPI issue

Jonathan 20 Reputation points
2026-02-03T14:23:41.73+00:00

Hi,

Can you help it below? How to fix it? Originally I was with this error "The type or namespace name 'OpenApi' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)"

User's image

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 10,490 Reputation points Microsoft External Staff Moderator
    2026-02-04T10:24:29.3533333+00:00

    Hi @Jonathan ,

    From your screenshots, it looks like your build is targeting net8.0, but you’ve installed Microsoft.AspNetCore.OpenApi 10.x. That version mismatch, plus a missing Microsoft.OpenApi reference, is what’s causing the CS0246 errors.

    You have a couple of options to fix it:

    Option A: Stay on .NET 8

    • In WebApp1.csproj, make sure you have:
    <TargetFramework>net8.0</TargetFramework>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.*" />
    <PackageReference Include="Microsoft.OpenApi" Version="1.6.*" />
    
    • Then clean and rebuild:
    dotnet clean
    # optionally delete bin and obj folders
    dotnet restore
    dotnet build
    

    Option B: Move to .NET 10

    • Install the .NET 10 SDK (check with dotnet --info to confirm 10.x).
    • Update your .csproj like this:
    <TargetFramework>net10.0</TargetFramework>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
    <PackageReference Include="Microsoft.OpenApi" Version="1.6.*" />
    
    • Then clean and rebuild as above.

    Finally, make sure any files using these types have:

    using Microsoft.OpenApi.Models;
    

    Try these and let me know the result.


3 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 82,596 Reputation points Volunteer Moderator
    2026-02-03T22:37:52.1133333+00:00

    show your project file. should look like:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
      <PropertyGroup>
        <TargetFramework>net10.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
      </ItemGroup>
    
    </Project>
    
    

    also try (after checking project file):

    % dotnet restore
    % dotnet build
    
    0 comments No comments

  2. Jonathan 20 Reputation points
    2026-02-04T01:17:01.41+00:00

    Here is the project details

    User's image


  3. Jack Dang (WICLOUD CORPORATION) 10,490 Reputation points Microsoft External Staff Moderator
    2026-02-04T06:59:45.67+00:00

    Hi @Jonathan ,

    Thanks for reaching out.

    The error you’re seeing (The type or namespace name 'OpenApi' does not exist…) usually happens if the OpenAPI package isn’t installed or if your project isn’t set up correctly. Here’s how to fix it step by step:

    1. Make sure your project uses the Web SDK and a supported framework in your .csproj:
    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>
        <TargetFramework>net10.0</TargetFramework> <!-- or net8.0/net9.0 -->
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
      </ItemGroup>
    </Project>
    
    1. Open PowerShell and navigate to your project folder:
    cd "C:\dp9_107\L0\Web_API\WebApp1"
    
    1. Add the OpenAPI package (if it’s not already in the .csproj):
    dotnet add package Microsoft.AspNetCore.OpenApi
    

    Tip: If you still see errors, specify the project file explicitly:

    dotnet add package Microsoft.AspNetCore.OpenApi --project "C:\dp9_107\L0\Web_API\WebApp1\WebApp1.csproj"
    
    1. Restore and build the project:
    dotnet restore
    dotnet build
    
    1. In your code, import the namespace where needed:
    using Microsoft.AspNetCore.OpenApi;
    

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.