Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
DinoHad opened this issue Jun 12, 2023 · 15 comments
Closed
1 task done

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

DinoHad opened this issue Jun 12, 2023 · 15 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Debugger-mono
Milestone

Comments

@DinoHad
Copy link

DinoHad commented Jun 12, 2023

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" });
      }
  }
@javiercn javiercn transferred this issue from dotnet/aspnetcore Jun 12, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 12, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 12, 2023
@vcsjones vcsjones added arch-wasm WebAssembly architecture area-Debugger-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 12, 2023
@ghost
Copy link

ghost commented Jun 12, 2023

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

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" });
      }
  }
Author: DinoHad
Assignees: -
Labels:

arch-wasm, untriaged, area-Debugger-mono

Milestone: -

@lewing lewing added this to the 7.0.x milestone Jun 12, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 12, 2023
@radical radical changed the title Blazor Wasm debugger not working anymore [wasm][7.0] Blazor Wasm debugger not working anymore Jun 12, 2023
@DinoHad
Copy link
Author

DinoHad commented Jun 14, 2023

Same issue with .NET (v7.0.304) and 7.0.7 packages.

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.7" />

Is there and advice or bypass to make debugger working again, our projects are totally blocked.

thank you guys.

@DinoHad
Copy link
Author

DinoHad commented Jun 14, 2023

When I open page which should hit debugger (method: OnInitializedAsync):

image

@DinoHad
Copy link
Author

DinoHad commented Jun 14, 2023

image

@ilonatommy
Copy link
Member

ilonatommy commented Jun 14, 2023

Thank you for the report, @DinoHad. I was trying to reproduce but with no effect so far. Generally this kind of error (getDotnetRuntime is not defined) should be displayed when the debugger action is triggered on non-wasm page. Let me ask you some questions.

  1. I got some wierd error on visual studio and in console

Did you try debugging in Browser (ctrl+alt+D on the browser's window) or only in Visual Studio? Does it finish with the same error for both?

  1. Does it happen only on your big project? What about a simple template project? Does it happen every time you trigger debugging action (hit breakpoint/step in etc) or only in specific situations?

  2. It is important to mention that i'm using authentication, (OpenIdDict).

Does it mean that if you remove the authentication from the project, the behavior changes?

  1. Can you reproduce the behavior on another computer?

@DinoHad
Copy link
Author

DinoHad commented Jun 14, 2023

Hi @ilonatommy , thank you for your respond!

  1. After we didn't success to debug via Visual studio, we tried to debugging in Browser but without success (we got some popup error 'websocket disconnected' sth like that.

  2. We have 5 projects in Blazor Wasm in different solutions and all of them are blocked now and they have same structure and architecture and all of them struggling with debugging. All Blazor Wasm projects rely on same Authentication structure with OpenIdDict because our projects are based on logged in user data and each operation on application required logged in user and information from that user.
    What we figured out is that AuthorizeRouteView is some kind of blocker, for example when we use App.razor from blank new project which doesn't have AuthorizeRouteView and only have RouteView debugger works, but it is useless for us because of need for data from logged in user.

  3. So, removing authentication helps to debugger to work again, yes. Actually as I mentioned above.

  4. Yes, it is same on other team members

@ilonatommy
Copy link
Member

ilonatommy commented Jun 16, 2023

I kind of reproduced on 7.0.5 when the app has another, authorization problem but am still looking for ways how to fail debugging a correctly set up application. In the meantime, please make sure your authorization setup is correct.
Repro steps:

  1. dotnet new blazorwasm --auth Individual or using the tutorial.
    Do not set up the db - authorization will fail for sure.
  2. Set a breakpoint on Authorize-guarded page - FetchData.razor.
    Result: "Frame not in module" in VS, as on the screenshot.
  3. Set up the authorization correctly with db connection. Run the app, breakpoint in FetchData is hit correctly.

Will keep you posted on the progress.

@DinoHad
Copy link
Author

DinoHad commented Jun 18, 2023

it seems comment of EricCornelson on this issue: #86754 (comment) resolved this one also, debugger/break points is now hitted, but there is still error persistent in console while App is running in Debug mode and debugger hit break point.
error:

[01:39:50] 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": "-2970997850457766499.5.9"
        },
        "exceptionDetails": {
          "exceptionId": 9,
          "text": "Uncaught",
          "lineNumber": 0,
          "columnNumber": 0,
          "scriptId": "514",
          "stackTrace": {
            "callFrames": [
              {
                "functionName": "",
                "scriptId": "514",
                "url": "",
                "lineNumber": 0,
                "columnNumber": 0
              }
            ]
          },
          "exception": {
            "type": "object",
            "subtype": "error",
            "className": "ReferenceError",
            "description": "ReferenceError: getDotnetRuntime is not defined\n    at <anonymous>:1:1",
            "objectId": "-2970997850457766499.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)

@thaystg
Copy link
Member

thaystg commented Jun 20, 2023

@DinoHad just to understand it better. If you use the @EricCornelson workaround the breakpoints are working fine for you now, right?
But you still see a weird message in the console, but this is not affecting the debugger experience, am I right?

@LongJohnBlackbeard
Copy link

LongJohnBlackbeard commented Jun 20, 2023

@DinoHad just to understand it better. If you use the @EricCornelson workaround the breakpoints are working fine for you now, right? But you still see a weird message in the console, but this is not affecting the debugger experience, am I right?

@EricCornelson dist.zip file worked for me. I am not getting any messages in the console though.

I did notice this in the debug console that was there before I did the dist.zip replacement, not sure if it is related:

BSSO Telemetry: {"result":"Error","error":"NoExtension","type":"ChromeSsoTelemetry","data":{},"traces":["BrowserSSO Initialized","Creating ChromeBrowserCore provider","Sending message for method CreateProviderAsync","Received message for method CreateProviderAsync","Error: ChromeBrowserCore error NoExtension: Extension is not installed."]}
Could not read source map for file:///X:/bt/1197332/repo/out/retail-amd64/Microsoft.Identity.UX.Telemetry/release/TelemetryHelper.js: ENOENT: no such file or directory, open 'x:\bt\1197332\repo\out\retail-amd64\Microsoft.Identity.UX.Telemetry\release\TelemetryHelper.js.map'
WARNING: Processing source-maps of https://aadcdn.msauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js took longer than 6298.3243 ms so we continued execution without waiting for all the breakpoints for the script to be set.Could not read source map for https://aadcdn.msauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js: Unexpected 404 response from https://aadcdn.msauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js.map: <?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.
RequestId:573dbfad-801e-000b-71ad-a31264000000
Time:2023-06-20T19:30:39.4938193Z</Message></Error>

@DinoHad
Copy link
Author

DinoHad commented Jun 21, 2023

@LongJohnBlackbeard Yes, exactly.

@ricardomomm
Copy link

@DinoHad just to understand it better. If you use the @EricCornelson workaround the breakpoints are working fine for you now, right? But you still see a weird message in the console, but this is not affecting the debugger experience, am I right?

@EricCornelson dist.zip file worked for me. I am not getting any messages in the console though.

I did notice this in the debug console that was there before I did the dist.zip replacement, not sure if it is related:

BSSO Telemetry: {"result":"Error","error":"NoExtension","type":"ChromeSsoTelemetry","data":{},"traces":["BrowserSSO Initialized","Creating ChromeBrowserCore provider","Sending message for method CreateProviderAsync","Received message for method CreateProviderAsync","Error: ChromeBrowserCore error NoExtension: Extension is not installed."]}
Could not read source map for file:///X:/bt/1197332/repo/out/retail-amd64/Microsoft.Identity.UX.Telemetry/release/TelemetryHelper.js: ENOENT: no such file or directory, open 'x:\bt\1197332\repo\out\retail-amd64\Microsoft.Identity.UX.Telemetry\release\TelemetryHelper.js.map'
WARNING: Processing source-maps of https://aadcdn.msauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js took longer than 6298.3243 ms so we continued execution without waiting for all the breakpoints for the script to be set.Could not read source map for https://aadcdn.msauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js: Unexpected 404 response from https://aadcdn.msauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js.map: <?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.
RequestId:573dbfad-801e-000b-71ad-a31264000000
Time:2023-06-20T19:30:39.4938193Z</Message></Error>

The dist.zip worked for me as well, no error messages.

@vsvsav
Copy link

vsvsav commented Jun 25, 2023

Github, where is the button "I have the same bug" ? I have the same bug on all 17.6.* Pro, on 17.6.4 it works only after VS reinstalling and only the first time. If you reopen VS it won't work. MS does not have good (complex) unit tests.

@puwalski
Copy link

Same problem in my VS but with Blazor WASM 6.0.5 and 6.0.19. The problem returns like a boomerang every few months and usually only disappears with the next Visual Studio update.

@lewing
Copy link
Member

lewing commented Jul 10, 2023

7.0.11 and 6.0.21 shoud have have a fix for this.

@lewing lewing closed this as completed Jul 10, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Debugger-mono
Projects
None yet
Development

No branches or pull requests

9 participants