Skip to content

install .net8.0 aot 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located #53125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
lozn00 opened this issue Jan 4, 2024 · 11 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates NativeAOT

Comments

@lozn00
Copy link

lozn00 commented Jan 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

My computer has .NET 8.0 installed but my project is configured with .NET 7.0 using ASP .NET Core Swagger, this project used to work correctly, I did some version upgrades to these libraries later, and I reinstalled my computer, resulting in these headaches

System.InvalidOperationException: A suitable constructor for type 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter'

have configured both the rd.xml and source generation related to AOT, but these issues have occurred due to the computer being reinstalled

Reproduction Steps

<ItemGroup>
		<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.4" />
		<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.4" />
		<PackageReference Include="Microsoft.AspNetCore.SignalR" Condition="$(DefineConstants.Contains('PUSH'))" Version="1.1.0" />
	
		<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
	
		<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
		<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.6" />
		<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
		<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
		
		<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
		<!--<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />-->
		<!--<PackageReference Include="System.Private.ServiceModel" Version="4.10.2" />-->
		<PackageReference Include="Dapper" Version="2.0.123" />
		<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
		<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
		<PackageReference Include="System.ServiceModel.Duplex" Version="4.8.*" />
		<PackageReference Include="System.ServiceModel.Federation" Version="4.8.*" />
		<PackageReference Include="System.ServiceModel.Http" Version="4.8.*" />
		<PackageReference Include="System.ServiceModel.NetTcp" Version="4.8.*" />
		<PackageReference Include="System.ServiceModel.Security" Version="4.8.*" />

	</ItemGroup>

<PropertyGroup>
		<PublishAot>true</PublishAot>
		<TargetFramework>net8.0</TargetFramework>
		<Nullable>enable</Nullable>
		<ImplicitUsings>enable</ImplicitUsings>
		<GenerateDocumentationFile>False</GenerateDocumentationFile>
		<Platforms>AnyCPU;x64</Platforms>
		<UserSecretsId>37c2da8e-4c70-4b1a-b525-dc02325e9e4c</UserSecretsId>
		<OutputType>Exe</OutputType>
		<DebugType>embedded</DebugType>
		<PlatformTarget>AnyCPU</PlatformTarget>
		<ErrorReport>send</ErrorReport>
		<IsPackable>false</IsPackable>
		<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
		<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
		<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
		<NoWin32Manifest>true</NoWin32Manifest>


code
 //开启权限小锁
 options.OperationFilter<AddResponseHeadersFilter>();
 options.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();

 //在header中添加token,传递到后台
 options.OperationFilter<SecurityRequirementsOperationFilter>();

Expected Behavior

open url display web

Steps To Reproduce

 //开启权限小锁
 options.OperationFilter<AddResponseHeadersFilter>();
 options.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();

 //在header中添加token,传递到后台
 options.OperationFilter<SecurityRequirementsOperationFilter>();

Exceptions (if any)

    Connection id "0HN0CSTITE29O", Request id "0HN0CSTITE29O:00000001": An unhandled exception was thrown by the application.
      System.InvalidOperationException: A suitable constructor for type 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.FindApplicableConstructor(Type, Type[], ConstructorInfo&, Nullable`1[]&) + 0xa1
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, Object[]) + 0x447
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.CreateFilter[TFilter](FilterDescriptor) + 0x61
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.<>c__DisplayClass4_0.<Configure>b__2(FilterDescriptor filterDescriptor) + 0x48
         at System.Collections.Generic.List`1.ForEach(Action`1) + 0x70
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.Configure(SwaggerGeneratorOptions) + 0x169
         at Microsoft.Extensions.Options.OptionsFactory`1.Create(String) + 0x176
         at Microsoft.Extensions.Options.UnnamedOptionsManager`1.get_Value() + 0x176
         at Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.<>c.<AddSwaggerGen>b__0_1(IServiceProvider s) + 0x3f
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite, RuntimeResolverContext) + 0x53
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument) + 0xe3
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext) + 0x77
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) + 0x2b8
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite, RuntimeResolverContext) + 0x142
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument) + 0x1c1
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext) + 0x77
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) + 0x2b8
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite, ServiceProviderEngineScope) + 0xc3
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass4_0.<RealizeService>b__0(ServiceProviderEngineScope scope) + 0x3d
         at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier, ServiceProviderEngineScope) + 0x137
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) + 0x76
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider, Type, Type) + 0x3a
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass8_0`1.<ReflectionFallback>b__0(T middleware, HttpContext context, IServiceProvider serviceProvider) + 0x105
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.ReflectionMiddlewareBinder.<>c__DisplayClass6_0.<CreateMiddleware>b__0(HttpContext context) + 0xd9
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(HttpContext context) + 0x8a
         at Microsoft.AspNetCore.Hosting.HostingApplication.ProcessRequestAsync(HostingApplication.Context) + 0x4e
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequests>d__238`1.MoveNext() + 0x49d
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN0CSTITE29O", Request id "0HN0CSTITE29O:00000002": An unhandled exception was thrown by the application.
      System.InvalidOperationException: A suitable constructor for type 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.FindApplicableConstructor(Type, Type[], ConstructorInfo&, Nullable`1[]&) + 0xa1
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, Object[]) + 0x447
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.CreateFilter[TFilter](FilterDescriptor) + 0x61
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.<>c__DisplayClass4_0.<Configure>b__2(FilterDescriptor filterDescriptor) + 0x48
         at System.Collections.Generic.List`1.ForEach(Action`1) + 0x70
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.Configure(SwaggerGeneratorOptions) + 0x169
         at Microsoft.Extensions.Options.OptionsFactory`1.Create(String) + 0x176
         at Microsoft.Extensions.Options.UnnamedOptionsManager`1.get_Value() + 0x176
         at Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.<>c.<AddSwaggerGen>b__0_1(IServiceProvider s) + 0x3f
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite, RuntimeResolverContext) + 0x53
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument) + 0xe3
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext) + 0x77
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) + 0x2b8
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite, RuntimeResolverContext) + 0x142
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument) + 0x1c1
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext) + 0x77
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) + 0x2b8
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite, ServiceProviderEngineScope) + 0xc3
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass4_0.<RealizeService>b__0(ServiceProviderEngineScope scope) + 0x3d
         at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier, ServiceProviderEngineScope) + 0x137
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) + 0x76
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider, Type, Type) + 0x3a
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass8_0`1.<ReflectionFallback>b__0(T middleware, HttpContext context, IServiceProvider serviceProvider) + 0x105
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.ReflectionMiddlewareBinder.<>c__DisplayClass6_0.<CreateMiddleware>b__0(HttpContext context) + 0xd9
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(HttpContext context) + 0x8a
         at Microsoft.AspNetCore.Hosting.HostingApplication.ProcessRequestAsync(HostingApplication.Context) + 0x4e
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequests>d__238`1.MoveNext() + 0x49d
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN0CSTITE29O", Request id "0HN0CSTITE29O:00000003": An unhandled exception was thrown by the application.
      System.InvalidOperationException: A suitable constructor for type 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.FindApplicableConstructor(Type, Type[], ConstructorInfo&, Nullable`1[]&) + 0xa1
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type, Object[]) + 0x447
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.CreateFilter[TFilter](FilterDescriptor) + 0x61
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.<>c__DisplayClass4_0.<Configure>b__2(FilterDescriptor filterDescriptor) + 0x48
         at System.Collections.Generic.List`1.ForEach(Action`1) + 0x70
         at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.Configure(SwaggerGeneratorOptions) + 0x169
         at Microsoft.Extensions.Options.OptionsFactory`1.Create(String) + 0x176
         at Microsoft.Extensions.Options.UnnamedOptionsManager`1.get_Value() + 0x176
         at Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.<>c.<AddSwaggerGen>b__0_1(IServiceProvider s) + 0x3f
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite, RuntimeResolverContext) + 0x53
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument) + 0xe3
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext) + 0x77
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) + 0x2b8
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite, RuntimeResolverContext) + 0x142
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument) + 0x1c1
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext) + 0x77
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) + 0x2b8
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite, ServiceProviderEngineScope) + 0xc3
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass4_0.<RealizeService>b__0(ServiceProviderEngineScope scope) + 0x3d
         at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier, ServiceProviderEngineScope) + 0x137
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) + 0x76
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider, Type, Type) + 0x3a
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass8_0`1.<ReflectionFallback>b__0(T middleware, HttpContext context, IServiceProvider serviceProvider) + 0x105
         at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.ReflectionMiddlewareBinder.<>c__DisplayClass6_0.<CreateMiddleware>b__0(HttpContext context) + 0xd9
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) + 0x1a8
         at Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(HttpContext context) + 0x8a
         at Microsoft.AspNetCore.Hosting.HostingApplication.ProcessRequestAsync(HostingApplication.Context) + 0x4e
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequests>d__238`1.MoveNext() + 0x49d


.NET Version

8.0

Anything else?

C:\src\netcorapibase>dotnet --info
.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.3b83835e

运行时环境:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100\

已安装 .NET 工作负载:
 Workload version: 8.0.100-manifests.3b83835e
没有要显示的已安装工作负载。

Host:
  Version:      8.0.0
  Architecture: x64
  Commit:       5535e31a71

.NET SDKs installed:
  5.0.405 [C:\Program Files\dotnet\sdk]
  7.0.104 [C:\Program Files\dotnet\sdk]
  7.0.202 [C:\Program Files\dotnet\sdk]
  8.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

@ghost ghost added needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically NativeAOT labels Jan 4, 2024
@lozn00 lozn00 changed the title install .net8.0 but csproject use .net7.0 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located install .net8.0 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located Jan 4, 2024
@lozn00 lozn00 changed the title install .net8.0 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located install .net8.0 aot 'Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter' could not be located Jan 4, 2024
@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

only run by visual studio some error

Microsoft.AspNetCore.Hosting.Diagnostics: Critical: Hosting startup assembly exception

System.InvalidOperationException: Startup assembly Microsoft.WebTools.ApiEndpointDiscovery failed to execute. See the inner exception for more details.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.WebTools.ApiEndpointDiscovery, Culture=neutral, PublicKeyToken=null'. 系统找不到指定的文件。
File name: 'Microsoft.WebTools.ApiEndpointDiscovery, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.ExecuteHostingStartups()
   --- End of inner exception stack trace ---
Microsoft.Hosting.Lifetime: Information: Application started. Press Ctrl+C to shut down.
Microsoft.Hosting.Lifetime: Information: Hosting environment: Development
Microsoft.Hosting.Lifetime: Information: Content root path: C:\src\netcorapibase

@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

I removed, OperationFilter related code, no error after packaging, but some controllers access all 404

so , this error should probably not be ignored when the development tools are running, System.InvalidOperationException: Startup assembly Microsoft.WebTools.ApiEndpointDiscovery failed to execute. I don't know how to fix this error

@martincostello
Copy link
Member

I doubt that Swashbuckle is inherently marked at AoT compatible or trim-friendly, and various parts of ASP.NET Core itself are not yet supported with AoT even in .NET 8, such as MVC, where a lot of the API Explorer code used for Open API support lives.

You could try rooting the Swashbuckle assemblies using to stop the AoT compiler from removing any of the types which might resolve the problem: https://learn.microsoft.com/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-8-0#root-assemblies

I think however your application's use cases are not currently supported for native AoT, in which case you'd either need to refactor things to only use Swashbuckle when native AoT is disabled, remove it completely, or wait until a time that MVC supports native AoT in some future major version of ASP.NET Core.

@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

Running in the development tool is normal, but after performing AOT, the controller is no longer accessible and seems to have been cropped

@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

@martincostello just deleted the code for the filter. Although this error did not occur, the entire controller disappeared and cannot be accessed. It shows 404 and can only access the code I configured on the homepage

app.MapGet("/", async context =>
{
 //   context.Response.Headers.Add("Content-Type", "text/html");
    await context.Response.WriteAsync("<a href=\"/swagger/index.html\">SWAGGER API</a><br/> <a href=\"/api/info\">SERVER BUILD INFO</a><br/> " +

});

this is worked ,but controller is cannot access ,404

@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

@martincostello In fact, AOT ,I have tested many new versions, 7.0.4 and previous versions, and I have solved the problems I encountered through rd.xml and source generation. However, I will encounter various strange problems in any subsequent version,

But I don't know how to solve it

@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

how to use ?
it 's like this?

	<ItemGroup>
		<!--<ProjectReference Include="..\MyLibrary\MyLibrary.csproj" />-->
		<TrimmerRootAssembly Include="Swashbuckle.AspNetCore" />
	</ItemGroup>

@martincostello
Copy link
Member

it 's like this?

Yes like that.

But I don't know how to solve it

Even if it happened to work before, native AoT is only supported in ASP.NET Core 8 but is not supported for all ASP.NET Core scenarios.

The supported, partially supported, and not supported scenarios are documented here.

@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

@martincostello thank you ,very very very

@lozn00
Copy link
Author

lozn00 commented Jan 4, 2024

May I ask how to use the controller normally after enabling AOT and prohibit deleting the MVC controller? Now accessing controller 404, I want to continue using it, @martincostello

@martincostello
Copy link
Member

I'm afraid I don't know - MVC is not supported with native AoT.

@mkArtakMSFT mkArtakMSFT added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Jan 10, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates NativeAOT
Projects
None yet
Development

No branches or pull requests

4 participants