Skip to content

ETag header not found error when running release build of app with compressed resources #63364

@ericstj

Description

@ericstj

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When fetching a file that's part of compressed payload the app throws the following exception:

System.InvalidOperationException
  HResult=0x80131509
  Message=ETag header not found.
  Source=Microsoft.AspNetCore.StaticAssets
  StackTrace:
   at Microsoft.AspNetCore.Builder.StaticAssetDescriptorExtensions.GetWeakETag(StaticAssetDescriptor descriptor) in Microsoft.AspNetCore.Builder\StaticAssetDescriptorExtensions.cs:line 47
   at Microsoft.AspNetCore.Builder.StaticAssetDevelopmentRuntimeHandler.AttachRuntimePatching(EndpointBuilder builder) in Microsoft.AspNetCore.Builder\StaticAssetDevelopmentRuntimeHandler.cs:line 153
   at Microsoft.AspNetCore.StaticAssets.StaticAssetEndpointFactory.Create(StaticAssetDescriptor resource, List`1 conventions, List`1 finallyConventions) in Microsoft.AspNetCore.StaticAssets\StaticAssetEndpointFactory.cs:line 41
   at Microsoft.AspNetCore.StaticAssets.StaticAssetsEndpointDataSource.UpdateEndpoints() in Microsoft.AspNetCore.StaticAssets\StaticAssetsEndpointDataSource.cs:line 89
   at Microsoft.AspNetCore.StaticAssets.StaticAssetsEndpointDataSource.Initialize() in Microsoft.AspNetCore.StaticAssets\StaticAssetsEndpointDataSource.cs:line 76
   at Microsoft.AspNetCore.StaticAssets.StaticAssetsEndpointDataSource.GetChangeToken() in Microsoft.AspNetCore.StaticAssets\StaticAssetsEndpointDataSource.cs:line 102
   at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration`1..ctor(Func`1 changeTokenProducer, Action`1 changeTokenConsumer, TState state)
   at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
   at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.CreateChangeTokenUnsynchronized(Boolean collectionChanged) in Microsoft.AspNetCore.Routing\CompositeEndpointDataSource.cs:line 197
   at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.EnsureChangeTokenInitialized() in Microsoft.AspNetCore.Routing\CompositeEndpointDataSource.cs:line 152
   at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.GetChangeToken() in Microsoft.AspNetCore.Routing\CompositeEndpointDataSource.cs:line 65
   at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.Initialize() in Microsoft.AspNetCore.Routing\DataSourceDependentCache.cs:line 57
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) in System.Threading\LazyInitializer.cs:line 81
   at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func`1 matcherBuilderFactory) in Microsoft.AspNetCore.Routing.Matching\DataSourceDependentMatcher.cs:line 58
   at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource) in Microsoft.AspNetCore.Routing.Matching\DfaMatcherFactory.cs:line 20
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync() in Microsoft.AspNetCore.Routing\EndpointRoutingMiddleware.cs:line 415
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<<Invoke>g__AwaitMatcher|10_0>d.MoveNext() in Microsoft.AspNetCore.Routing\EndpointRoutingMiddleware.cs:line 285

See details in dotnet/runtime#118914

When flowing SDK back to runtime which has tests that create ASP.NET apps and run them, they started failing when dotnet/sdk@952f759 reached us. This seems to make the ETag values only weak when the application is built in Debug configuration.

It looks to me like this change might disagree with the behavior of StaticAssetDevelopmentRuntimeHandler. It looks like that component is enabled when the ManifestType is Build (vs Publish) and that component insists on having weak ETag value

People do run web apps that are just Built and not Published in Release so it seems that there's some disagreement here between build targets and runtime.

Expected Behavior

No exception

Steps To Reproduce

Presumably a dotnet run -c Release on a wasm app would reproduce this (or whatever other type of app that uses compressed assets).

Exceptions (if any)

No response

.NET Version

dotnet/dotnet dotnet/dotnet@c4dc560

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions