Search code examples
progressive-web-appsblazor-webassembly

Blazor wasm pwa dependency injection error after publishing


We have a Blazor WASM PWA app that we're publishing locally for testing (standalone app, without any backend on the same site):

dotnet publish "$directorypath\Demo.Web.csproj" -c Release -o $destination

Publishing seems to go fine, but when we try to load the site, we end up getting the following error:

blazor.webassembly.js:1 System.AggregateException: AggregateException_ctor_DefaultMessage (TrimmingAnnotationsDoNotMatch_NewConstraint, MyHelper`1, IMyHelper`1)
 ---> System.ArgumentException: TrimmingAnnotationsDoNotMatch_NewConstraint, Helpers.FluentValidationEditContext`1, Helpers.IFluentValidationEditContext`1
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.ValidateTrimmingAnnotations(Type , Type[] , Type , Type[] )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.Populate()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory..ctor(ICollection`1 )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 , ServiceProviderOptions )
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection , ServiceProviderOptions )
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection , Boolean )
   at Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.<>c__DisplayClass5_0.<.ctor>b__0()
   at Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.Build()
   at Program.<Main>$(String[] args)
   Exception_EndOfInnerExceptionStack
callEntryPoint @ blazor.webassembly.js:1

Any idea on what's going on here? The app runs fine from the cmd line.

Thanks


Solution

  • Well, the issue was that the generic interface and its implementation didn't have the same restrictions applied to the generic type parameter T.