aspnetcore: After adding NuGet Package Microsoft.Extensions.Apidescription.Server to ASP.NET Web Project, build failed with error: Unable to find service type 'Microsoft.Extensions.ApiDescriptions.IDocumentProvider' in loaded assemblies
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
To Reproduce
- Install .NET 9.0 preview 7 latest-released-build on win11-x64
- Create a MVC Individual project and build it, build succeeded now:
dotnet new mvc -au Individual
dotnet build
- Add a NuGet Package(Microsoft.Extensions.Apidescription.Server) and build it again
dotnet add package Microsoft.Extensions.Apidescription.Server -v 9.0.0-preview.7.24406.2
dotnet build
Actual Result
Build failed with below errors:
Error Message:
Restore succeeded with 1 warning(s) in 0.9s C:\Users\v-qushi\source\repos\MVC\MVC.csproj : warning NU1904: Package ‘System.Drawing.Common’ 4.7.0 has a known critical severity vulnerability, https://github.com/advisories/GHSA-rxg9-xrhp-64gj You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy MVC failed with 2 error(s) and 1 warning(s) (9.4s) → bin\Debug\net9.0\MVC.dll C:\Users\v-qushi\source\repos\MVC\MVC.csproj : warning NU1904: Package ‘System.Drawing.Common’ 4.7.0 has a known critical severity vulnerability, https://github.com/advisories/GHSA-rxg9-xrhp-64gj C:\Users\v-qushi.nuget\packages\microsoft.extensions.apidescription.server\9.0.0-preview.7.24406.2\build\Microsoft.Extensions.ApiDescription.Server.targets(66,5): error : Unable to find service type ‘Microsoft.Extensions.ApiDescriptions.IDocumentProvider’ in loaded assemblies. C:\Users\v-qushi.nuget\packages\microsoft.extensions.apidescription.server\9.0.0-preview.7.24406.2\build\Microsoft.Extensions.ApiDescription.Server.targets(66,5): error MSB3073: The command "dotnet “C:\Users\v-qushi.nuget\packages\microsoft.extensions.apidescription.server\9.0.0-preview.7.24406.2\build../tools/dotnet-getdocument.dll” --assembly “C:\Users\v-qushi\source\repos\MVC\bin\Debug\net9.0\MVC.dll” --file-list “obj\MVC.OpenApiFiles.cache” --framework “.NETCoreApp,Version=v9.0” --output “obj” --project “MVC” --assets-file “C:\Users\v-qushi\source\repos\MVC\obj\project.assets.json” --platform “AnyCPU” " exited with code 10.
Build failed with 2 error(s) and 2 warning(s) in 10.9s
Expected Behavior
Build succeed.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
9.0.100-preview.7.24407.12
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23 (10 by maintainers)
@martincostello, sorry about that.
@captainsafia
Thank you so much! Your response cleared the whole thing to me.
Turns out that in my case it was because when
PublishAoT=trueis set, my code runs in a way (via checkingRuntimeFeature.IsDynamicCodeSupported == true) that means that the Swashbuckle services aren’t registered with the service collection.This then means the call here doesn’t include
Swashbuckle.AspNetCore.SwaggerGen, so no implementations ofMicrosoft.Extensions.ApiDescriptions.IDocumentProviderare found:https://github.com/dotnet/aspnetcore/blob/06155c05af89c957de20d2c53cee0e37171b9a09/src/Tools/GetDocumentInsider/src/Commands/GetDocumentCommandWorker.cs#L194
I can workaround this by only setting
PublishAot=trueduringdotnet publish, rather than always setting it to true in thecsprojfile.