Giter Club home page Giter Club logo

After adding NuGet Package Microsoft.Extensions.Apidescription.Server to ASP.NET Web Project, publish failed with error: Unable to find service type 'Microsoft.Extensions.ApiDescriptions.IDocumentProvider' in loaded assemblies about aspnetcore HOT 13 OPEN

v-qushi avatar v-qushi commented on August 25, 2024
After adding NuGet Package Microsoft.Extensions.Apidescription.Server to ASP.NET Web Project, publish failed with error: Unable to find service type 'Microsoft.Extensions.ApiDescriptions.IDocumentProvider' in loaded assemblies

from aspnetcore.

Comments (13)

v-qushi avatar v-qushi commented on August 25, 2024 2

@martincostello, sorry about that.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UserSecretsId>aspnet-MVCTest1-7cbb08a3-0196-42e4-8f3a-5de650cb96e4</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <None Update="app.db" CopyToOutputDirectory="PreserveNewest" ExcludeFromSingleFile="true" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.0-preview.6.24328.4" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0-preview.6.24328.4" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="9.0.0-preview.6.24328.4" />
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-preview.6.24328.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0-preview.6.24327.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0-preview.6.24327.4" />
    <PackageReference Include="Microsoft.Extensions.Apidescription.Server" Version="9.0.0-preview.6.24328.4">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

from aspnetcore.

v-qushi avatar v-qushi commented on August 25, 2024

It can also repro with .NET 8.0 project.

Not sure if it's a reasonable scenario. Why I try to add Nuget Package 'Microsoft.Extensions.Apidescription.Server' : when I do config 'Microsoft Power Power Platform', I met this issue: BUG 2110144. After doing the workaround adding Nuget package can resolve this issue. I aslo added the error message comment for doing publish using VS to BUG 2110144. The error message is different.
image

@mkArtakMSFT, can you please take a look at if it is a real issue for .NET SDK?
CC: @balachir

from aspnetcore.

captainsafia avatar captainsafia commented on August 25, 2024

@v-qushi Is the Microsoft.AspNetCore.OpenApi package installed in your project? If not, try installing it and see if this issue continues to repro.

 dotnet add package Microsoft.AspNetCore.OpenApi -v 9.0.0-preview.6.24324.2

from aspnetcore.

v-qushi avatar v-qushi commented on August 25, 2024

Checked my project, the package isn't installed.
I tried to install it, the issue still can repro.
publish PNG

from aspnetcore.

martincostello avatar martincostello commented on August 25, 2024

Add an explicit PackageReference for a newer version of System.Drawing.Common, or if you use central package management add an explicit PackageVersion of the same and set CentralPackageTransitivePinningEnabled to true.

from aspnetcore.

v-qushi avatar v-qushi commented on August 25, 2024

I can work around the system drawing common warnings by installing a newer version of it, but that does not take care of the actual publish failure itself
image

from aspnetcore.

captainsafia avatar captainsafia commented on August 25, 2024

@v-qushi Can you share the contents of the project file for your MvcTest1.csproj?

from aspnetcore.

v-qushi avatar v-qushi commented on August 25, 2024

@captainsafia Create new MVC Individual project, MvcTest1.csproj as below:
image

After add package Microsoft.Extensions.Apidescription.Server and Microsoft.AspNetCore.OpenApi:
image

from aspnetcore.

martincostello avatar martincostello commented on August 25, 2024

@v-qushi Can you provide the actual XML rather than a screenshot of it please? It's a lot easier for people to use, rather than needing to manually transcribe and type it out.

from aspnetcore.

matus-gazo avatar matus-gazo commented on August 25, 2024

Hi all, any news on this please? I am having same issue on .NET 8. While I can build and run the sub-project using OpenAPI/Swashbuckle, publish on the solution fails with same error for.

1>C:\Users\matgazo\.nuget\packages\microsoft.extensions.apidescription.server\8.0.7\build\Microsoft.Extensions.ApiDescription.Server.targets(66,5): error : Unable to find service type 'Microsoft.Extensions.ApiDescriptions.IDocumentProvider' in dependency injection container. Update the 'Startup' class to register a document.

EDIT: I worked around by setting <OpenApiGenerateDocuments>false</OpenApiGenerateDocuments> in my .csproj as Swagger UI still works just fine with this.

from aspnetcore.

captainsafia avatar captainsafia commented on August 25, 2024

@matus-gazo If you're running into this issue in .NET 8, I'd recommend upgrading to the latest version of the Swashbuckle package that targets the .NET 8 TFM and seeing if you still repro.

@v-qushi Can you email me a ZIP folder of the project that you are reproing this issue on?

from aspnetcore.

v-qushi avatar v-qushi commented on August 25, 2024

@captainsafia , I already sent you the email.

from aspnetcore.

v-qushi avatar v-qushi commented on August 25, 2024

@captainsafia , 'dotnet build' failed with the same 2 errors after adding the package.

from aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.