Skip to content

Publishing a blazor wasm app throws a Mono Linker exception in .NET 7.0 Preview 6 #2903

@Stamo-Gochev

Description

@Stamo-Gochev

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Link to a repository that demonstrates the bug:
https://github.com/Stamo-Gochev/blazor-linker-issue

Publishing a blazor wasm app with a custom component rendered in a RenderFragment throws a Mono Linker exception.

The setup has the following specifics:

  1. The blazor wasm app that is used for testing is the standard .NET 7.0 project template - nothing specific here
  2. A Razor Class Library is added as a dependency to the blazor wasm app
  3. A custom component from the Razor Class Library is rendered in the sample page in the blazor wasm app.
  4. The custom component renders itself in another component that itself just renders its ChildContent fragment.

The blazor wasm app is runnable without errors, the problem is reproducible when the app is published (when linker trimming is executed).

Expected Behavior

No exception is thrown.

Steps To Reproduce

  1. Clone https://github.com/Stamo-Gochev/blazor-linker-issue
  2. Navigate to https://github.com/Stamo-Gochev/blazor-linker-issue/tree/master/BlazorLinkerIssue/BlazorLinkerIssue/Server
  3. Run
dotnet publish -c Release BlazorLinkerIssue.Server.csproj

Note: A global.json file explicitly targets .NET 7.0 Preview 6. If the project is built with .NET 7.0 Preview 5, i.e. if you use:

{
    "sdk": {
        "version": "7.0.100-preview.5.22307.18"
    }
}

instead, then the project is published successfully.


Here are the logs of the publish output:

Exceptions (if any)

An error is thrown:

MSBuild version 17.3.0-preview-22329-01+77c72dd0f for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.100-preview.6.22352.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(219,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [D:\...\blazor-linker-issue\BlazorLinkerIssue\BlazorLinkerIssue\Server\BlazorLinkerIssue.Server.csproj]
C:\Program Files\dotnet\sdk\7.0.100-preview.6.22352.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(219,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [D:\...\blazor-linker-issue\BlazorLinkerIssue\CustomComponents\CustomComponents.csproj]
C:\Program Files\dotnet\sdk\7.0.100-preview.6.22352.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(219,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [D:\...\blazor-linker-issue\BlazorLinkerIssue\BlazorLinkerIssue\Shared\BlazorLinkerIssue.Shared.csproj]
  CustomComponents -> D:\...\blazor-linker-issue\BlazorLinkerIssue\CustomComponents\bin\Release\net7.0\CustomComponents.dll
  BlazorLinkerIssue.Shared -> D:\...\blazor-linker-issue\BlazorLinkerIssue\BlazorLinkerIssue\Shared\bin\Release\net7.0\BlazorLinkerIssue.Shared.dll
  BlazorLinkerIssue.Client -> D:\...\blazor-linker-issue\BlazorLinkerIssue\BlazorLinkerIssue\Client\bin\Release\net7.0\BlazorLinkerIssue.Client.dll
  BlazorLinkerIssue.Client (Blazor output) -> D:\...\blazor-linker-issue\BlazorLinkerIssue\BlazorLinkerIssue\Client\bin\Release\net7.0\wwwroot
  BlazorLinkerIssue.Server -> D:\...\blazor-linker-issue\BlazorLinkerIssue\BlazorLinkerIssue\Server\bin\Release\net7.0\BlazorLinkerIssue.Server.dll
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.
  Stack overflow.
     at Mono.Linker.Steps.MarkStep.MarkType(Mono.Cecil.TypeReference, Mono.Linker.DependencyInfo, System.Nullable`1<Mono.Linker.MessageOrigin>)
     at Mono.Linker.Steps.MarkStep.MarkGenericArguments(Mono.Cecil.IGenericInstance)

Full log can be fount at:
https://github.com/Stamo-Gochev/blazor-linker-issue/blob/master/BlazorLinkerIssue/BlazorLinkerIssue/Server/publish-output-net7-preview6.txt

.NET Version

7.0.100-preview.6.22352.1

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions