Properly mark assembly non-trimmable when using Blazor Webassembly

39 Views Asked by At

(This question is also part of Lazy load not trimmable assembly with (or without) AOT - entangled with that topic, but IMHO valid also as a separate issue; and I have also created a git issue: https://github.com/dotnet/runtime/issues/96620)

I have a library in my client application that I need to have untrimmed. Hence, following the documentation I have added it to the .csproj:

<ItemGroup>
  <TrimmerRootAssembly Include="Blazicons.MaterialDesignIcons" />
</ItemGroup>

The dll is trimmed during publishing despite the setting. This results in an integrity check error in the browser. The dll is intact, the compressed versions however are trimmed (I have checked, they really are). Which is weird on its own. The compressed+trimmed version is served, but the checksum seems to be the wrong one anyway.

Failed to find a valid digest in the 'integrity' attribute for resource 'https://.../_framework/Blazicons.MaterialDesignIcons.dll' with computed SHA-256 integrity 'gMXbZ3OfWdujY73B/l1KFNoubyP8nqgEYJ/OZjVnvaM='. The resource has been blocked.

trimming disabled

Removing TrimmerRootAssembly makes this error go away, and makes the sizes be in sync:

trimming enabled

I am using IIS. With the following web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
  <system.webServer>
    <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\RemoteService.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <handlerSettings>
            <handlerSetting name="enableShadowCopy" value="true" />
            <handlerSetting name="shadowCopyDirectory" value="../ShadowCopyDirectory/" />
        </handlerSettings>
    </aspNetCore>
    <staticContent>
      <remove fileExtension=".blat" />
      <remove fileExtension=".dat" />
      <remove fileExtension=".dll" />
      <remove fileExtension=".webcil" />
      <remove fileExtension=".json" />
      <remove fileExtension=".wasm" />
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".blat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".webcil" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".wasm" mimeType="application/wasm" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
    </staticContent>
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/octet-stream" enabled="true" />
        <add mimeType="application/wasm" enabled="true" />
      </dynamicTypes>
    </httpCompression>
    <rewrite>
      <rules>
        <clear />
        <rule name="Redirect to https" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  </location>
</configuration>
0

There are 0 best solutions below