Skip to content

[wasm][7.0] Blazor Wasm debugger not working anymore #87407

@DinoHad

Description

@DinoHad

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When I try to debug my Blazor Wasm application (cs files), I got stucked with debugger. Debugger not hit and I got some wierd error on visual studio and in console. I didn't find any resolution during my research last 5 days.
I need help ASAP because we really cannot accept situations like this, We are big fan of Blazor and .NET stack but unfortunatelly if we do not solve this issue we cannot continue our projects in this technology, it is not acceptable to have issues like this.

It worked before but now there is no chance to make it work again. I didn't change anything in my code base but windows updates, visual studio update.

I did re-installed all SDK-s, re-installed visual studio, even check .NET core 8 preview, but without success.

It is important to mention that i'm using authentication, (OpenIdDict).
.NET 7, VS 17.6.2

Expected Behavior

Expecting to have working debbuger breakpoints inside razor.cs files.

Steps To Reproduce

Exceptions (if any)

[14:07:12] fail: DevToolsProxy[0]
      failed: Microsoft.WebAssembly.Diagnostics.DebuggerAgentException: SendDebuggerAgentCommand failed for GetAssemblyByName: [Result: IsOk: False, IsErr: True, Value: , Error: {
        "result": {
          "type": "object",
          "subtype": "error",
          "className": "ReferenceError",
          "description": "ReferenceError: getDotnetRuntime is not defined\n    at <anonymous>:1:1",
          "objectId": "8627393451561219652.5.9"
        },
        "exceptionDetails": {
          "exceptionId": 9,
          "text": "Uncaught",
          "lineNumber": 0,
          "columnNumber": 0,
          "scriptId": "518",
          "stackTrace": {
            "callFrames": [
              {
                "functionName": "",
                "scriptId": "518",
                "url": "",
                "lineNumber": 0,
                "columnNumber": 0
              }
            ]
          },
          "exception": {
            "type": "object",
            "subtype": "error",
            "className": "ReferenceError",
            "description": "ReferenceError: getDotnetRuntime is not defined\n    at <anonymous>:1:1",
            "objectId": "8627393451561219652.5.10"
          }
        }
      } ]
         at Microsoft.WebAssembly.Diagnostics.MonoSDBHelper.SendDebuggerAgentCommand[T](T command, MonoBinaryWriter arguments, CancellationToken token, Boolean throwOnError)
         at Microsoft.WebAssembly.Diagnostics.MonoSDBHelper.GetAssemblyId(String asm_name, CancellationToken token)
         at Microsoft.WebAssembly.Diagnostics.MonoProxy.SetMonoBreakpoint(SessionId sessionId, String reqId, SourceLocation location, String condition, CancellationToken token)
         at Microsoft.WebAssembly.Diagnostics.MonoProxy.SetBreakpoint(SessionId sessionId, DebugStore store, BreakpointRequest req, Boolean sendResolvedEvent, Boolean fromEnC, CancellationToken token)
         at Microsoft.WebAssembly.Diagnostics.MonoProxy.OnSourceFileAdded(SessionId sessionId, SourceFile source, ExecutionContext context, CancellationToken token)
         at Microsoft.WebAssembly.Diagnostics.MonoProxy.LoadStore(SessionId sessionId, Boolean tryUseDebuggerProtocol, CancellationToken token)
         at Microsoft.WebAssembly.Diagnostics.MonoProxy.LoadStore(SessionId sessionId, Boolean tryUseDebuggerProtocol, CancellationToken token)

error

.NET Version

7.0.302

Anything else?

Dotnet Info:

dotnet --info
.NET SDK:
 Version:   7.0.302
 Commit:    990cf98a27

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.302\

Host:
  Version:      7.0.5
  Architecture: x64
  Commit:       8042d61b17

.NET SDKs installed:
  5.0.402 [C:\Program Files\dotnet\sdk]
  6.0.100 [C:\Program Files\dotnet\sdk]
  6.0.401 [C:\Program Files\dotnet\sdk]
  7.0.101 [C:\Program Files\dotnet\sdk]
  7.0.203 [C:\Program Files\dotnet\sdk]
  7.0.302 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

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

Environment variables:
  Not set

global.json file:
  Not found

Project.cs

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

	<PropertyGroup>
		<TargetFramework>net7.0</TargetFramework>
		<Nullable>enable</Nullable>
		<ImplicitUsings>enable</ImplicitUsings>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
		<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
		<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.5" />
		<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.5" />
		<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
		<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.5" />
		<PackageReference Include="MudBlazor" Version="6.4.1" />
		<PackageReference Include="FluentValidation" Version="11.5.2" />
	</ItemGroup>

	<ItemGroup>
	  <ProjectReference Include="..\Common.Dtos\Common.Dtos.csproj" />
	  <ProjectReference Include="..\Common.Enums\Common.Enums.csproj" />
	</ItemGroup>

	<ItemGroup>
		<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
	</ItemGroup>

	<PropertyGroup>
		<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
	</PropertyGroup>

</Project>

App.razor

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                    @if (!context.User.Identity.IsAuthenticated)
                    {
                        <RedirectToLogin />
                    }
                    else
                    {
                        <p>You are not authorized to access this resource.</p>
                    }
                </NotAuthorized>
                <Authorizing>
                </Authorizing>
            </AuthorizeRouteView>
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

Example of some page which requires Authenticated user

@page "/"

@attribute [Authorize(Roles = "TENANT")]

<h1>test</h1>

Index.html Scripts:

    <script src="_framework/blazor.webassembly.js"></script>
    <script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
    <script src="_content/MudBlazor/MudBlazor.min.js"></script>

Program.cs

using Cockpit.Blazor;
using Cockpit.Blazor.Auth;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.JSInterop;
using MudBlazor.Services;
using System.Globalization;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddLocalization();

CultureInfo cultureInfo;
var jsInterop = builder.Build().Services.GetRequiredService<IJSRuntime>();
var appLanguage = await jsInterop.InvokeAsync<string>("appCulture.get");

if (appLanguage != null)
{
   cultureInfo = new CultureInfo(appLanguage);
}
else
{
   cultureInfo = new CultureInfo("en-US");
   await jsInterop.InvokeVoidAsync("appCulture.set", "en-US");
}

CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

builder.Services.AddMudServices();

builder.Services.AddTransient<BlazorWasmAPIsAuthorizationMessageHandler>();

builder.Services.AddHttpClient("CommunityAPI", client => client.BaseAddress = new Uri("https://localhost:7121/")).AddHttpMessageHandler<BlazorWasmAPIsAuthorizationMessageHandler>();
builder.Services.AddHttpClient("MembershipAPI", client => client.BaseAddress = new Uri("https://localhost:7257/")).AddHttpMessageHandler<BlazorWasmAPIsAuthorizationMessageHandler>();
builder.Services.AddHttpClient("NotificationAPI", client => client.BaseAddress = new Uri("https://localhost:7099/")).AddHttpMessageHandler<BlazorWasmAPIsAuthorizationMessageHandler>();
builder.Services.AddHttpClient("OrderAPI", client => client.BaseAddress = new Uri("https://localhost:7056/")).AddHttpMessageHandler<BlazorWasmAPIsAuthorizationMessageHandler>();
builder.Services.AddHttpClient("TenantAPI", client => client.BaseAddress = new Uri("https://localhost:7221/")).AddHttpMessageHandler<BlazorWasmAPIsAuthorizationMessageHandler>();

builder.Services.AddOidcAuthentication(options =>
{
   options.ProviderOptions.ClientId = "cockpit-client";
   options.ProviderOptions.Authority = "https://localhost:7060";
   options.ProviderOptions.ResponseType = "code";
   options.ProviderOptions.RedirectUri = "https://localhost:7236/authentication/login-callback";
   options.ProviderOptions.PostLogoutRedirectUri = "https://localhost:7236/authentication/logout-callback";
   options.ProviderOptions.ResponseMode = "query";

   options.AuthenticationPaths.RemoteRegisterPath = "https://localhost:7060/Identity/Account/Register";

   options.ProviderOptions.DefaultScopes.Add("openid");
   options.ProviderOptions.DefaultScopes.Add("roles");
   options.ProviderOptions.DefaultScopes.Add("email");
   options.ProviderOptions.DefaultScopes.Add("profile");
   options.ProviderOptions.DefaultScopes.Add("apis");

   options.UserOptions.RoleClaim = "role";
});

await builder.Build().RunAsync();

BlazorWasmAPIsAuthorizationMessageHandler.cs

  public class BlazorWasmAPIsAuthorizationMessageHandler : AuthorizationMessageHandler
  {
      public BlazorWasmAPIsAuthorizationMessageHandler(IAccessTokenProvider provider,
      NavigationManager navigationManager)
      : base(provider, navigationManager)
      {
          ConfigureHandler(
              authorizedUrls: new[] { "https://localhost:7121", "https://localhost:7257", "https://localhost:7099", "https://localhost:7056", "https://localhost:7221" },
              scopes: new[] { "email", "profile", "roles", "openid", "apis" });
      }
  }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions