Lapiniot / Net.MQTT

0 stars 0 forks source link

Blazor interactive rendering stops working after assembly trimming #9

Closed Lapiniot closed 3 months ago

Lapiniot commented 3 months ago

Blazor interactive rendering doesn't work anymore when application is published with trimming enabled. Client requests reach server app, but UI fragments are not updated in response. Browser logs contain following:

blazor.web.js:1 Uncaught (in promise) Error: Found malformed component comment at Blazor:{"type":"server","prerenderId":"12e60bb585924b5e99c68fa127b785e8","key":{"locationHash":"9F118AE1A8DFCA4AA63AF0A65FA2BDF8C08A2C1BD3F462BE9FFBE8532856BB2E:0","formattedComponentKey":""}} at Dt (blazor.web.js:1:43034) at Tt (blazor.web.js:1:41614) at Tt (blazor.web.js:1:41687) at Tt (blazor.web.js:1:41687) at Tt (blazor.web.js:1:41687) at Tt (blazor.web.js:1:41687) at Tt (blazor.web.js:1:41687) at blazor.web.js:1:40877 at _t (blazor.web.js:1:40929) at wi (blazor.web.js:1:171835)

Lapiniot commented 3 months ago

There are no obvious errors in the log that can shed light on the issue directly. However, after some experimentation with trimming configuration it become clear that issue is caused by some dynamic code trimmed off from one of the .NET standard libraries. So we essentially have two options:

Lapiniot commented 3 months ago

It appeared after some trials that following assemblies should be skipped from trimming:

How to quickly narrow down the list of "victims":

  1. set

\partial\

in the Directory.Build.props

  1. Run dotnet publish

dotnet publish -c Release -p:PublishTrimmed=true -p:SelfContained=true

  1. Run

printf '\\n' *.dll

in the publish directory to get pre-formated list of all dependencies kept by linker

  1. Add this list to Mqtt.Server.csproj as project items
  2. Publish with trimming again and test
  3. Simply bisect the list and repeat prev. step to figure out which assemblies cause issues