dotnet / dotnet/sdk

Runtime error with Blazor Server projects that include an MSBuild target depending on the CoreBuild target. (.NET SDK Preview 7)

Open
#43,225 0 comments 8 reactions 0 assignees View on GitHub
Area-Workloads untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

I need to include the output files of my source generator to static web assets. So, I appended the following MSBuild target in a Blazor Server project file to follow @javiercn's advice, such as https://github.com/jsakamoto/Toolbelt.Blazor.I18nText/issues/63#issue-2395631723 and https://github.com/dotnet/sdk/issues/43120#issuecomment-2326059962.

```xml
...





...
```

That looked to be working fine, but when I ran it with the .NET SDK 9 Preview 7, it reported a runtime error on the root URL request. The error message in the server console is below.

```
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.

System.InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /_Host, area: }.

at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DynamicPageEndpointMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatch|10_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
```

![image](https://github.com/user-attachments/assets/9d643fe6-32cb-4f85-bb36-eb3fa9162429)

### To Reproduce

Build and run the project I attached to this issue below with the .NET SDK 9 Preview 7. Then you will see the error messages I explained above.

[📦NET9SWAServer.zip](https://github.com/user-attachments/files/16870331/NET9SWAServer.zip)

### Reviewing the past issue

When I configured the MSBuild script like the one below, it happened to build errors on a multi-targeting Razor Class Library project. (See also: https://github.com/dotnet/sdk/issues/43120)

```xml
...





...
```

So, I fixed that issue by changing the `BeforeTargets` attribute value in the MSBuild script like the one below.

```xml
...





...
```

However, as I reported above, this time, it caused a runtime error when running a Blazor Server app.

### Conslusion

Again, I need to include the output files of my source generator as static web assets with the .NET 9 SDK on all kinds of Blazor projects, such as Blazor WebAssembly apps, Blazor Server apps, and Razor Class Libraries. It also must work fine regardless of whether those are multi-targeting or not and regardless of target framework versions (*not the SDK version), such as .NET 6.0, 8.0, and 9.0.

What can I do? Any advice would be helpful.
Thank you in advance for your help.

### Further technical details

#### The output of the `dotnet --info`

dotnet --info

```
.NET SDK:
Version: 9.0.100-preview.7.24407.12
Commit: d672b8a045
Workload version: 9.0.100-manifests.baed1e37
MSBuild version: 17.12.0-preview-24374-02+48e81c6f1

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100-preview.7.24407.12\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
[android]
Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
Manifest Version: 35.0.0-preview.7.41/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.android\35.0.0-preview.7.41\WorkloadManifest.json
Install Type: Msi

[aspire]
Installation Source: SDK 9.0.100-preview.7, VS 17.11.35208.52
Manifest Version: 8.1.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json
Install Type: FileBased

[ios]
Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
Manifest Version: 17.5.9231-net9-p7/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.ios\17.5.9231-net9-p7\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
Manifest Version: 17.5.9231-net9-p7/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.maccatalyst\17.5.9231-net9-p7\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166, VS 17.11.35208.52
Manifest Version: 9.0.0-preview.7.24407.4/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.sdk.maui\9.0.0-preview.7.24407.4\WorkloadManifest.json
Install Type: Msi

[wasm-tools]
Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166
Manifest Version: 9.0.0-preview.7.24405.7/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.current\9.0.0-preview.7.24405.7\WorkloadManifest.json
Install Type: Msi

[wasm-tools-net6]
Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166
Manifest Version: 9.0.0-preview.7.24405.7/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.net6\9.0.0-preview.7.24405.7\WorkloadManifest.json
Install Type: Msi

[wasm-tools-net7]
Installation Source: SDK 9.0.100-preview.7, VS 17.12.35209.166
Manifest Version: 9.0.0-preview.7.24405.7/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.net7\9.0.0-preview.7.24405.7\WorkloadManifest.json
Install Type: Msi

[wasm-tools-net8]
Installation Source: SDK 9.0.100-preview.7
Manifest Version: 9.0.0-preview.7.24405.7/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.net8\9.0.0-preview.7.24405.7\WorkloadManifest.json
Install Type: Msi

Host:
Version: 9.0.0-preview.7.24405.7
Architecture: x64
Commit: static

.NET SDKs installed:
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.425 [C:\Program Files\dotnet\sdk]
7.0.410 [C:\Program Files\dotnet\sdk]
8.0.400 [C:\Program Files\dotnet\sdk]
9.0.100-preview.7.24407.12 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0-preview.7.24406.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0-preview.7.24405.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0-preview.7.24405.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
C:\Projects\Feedbacks\Blazor\Net9andStaticWebAssets\RCL\global.json

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.