Skip to content

Conversation

@kevinbayter
Copy link

@kevinbayter kevinbayter commented Aug 5, 2025

Fix Blazor WebAssembly SDK Configuration

🐛 Problem

The NPacMan.Blazor project had an incorrect SDK configuration (Microsoft.NET.Sdk.Web) instead of the specific Blazor WebAssembly SDK (Microsoft.NET.Sdk.BlazorWebAssembly). This caused the following errors:

  • ❌ 404 error when loading blazor.webassembly.js
  • ❌ JavaScript error: "Cannot read properties of undefined (reading 'invokeMethodAsync')"
  • window.DotNet was not available
  • ❌ Blazor WebAssembly framework files were not generated correctly

🔧 Solution

Changed the SDK in src/NPacMan.Blazor/NPacMan.Blazor.csproj:

- <Project Sdk="Microsoft.NET.Sdk.Web">
+ <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

Results

After the change and rebuild:

  • blazor.webassembly.js is served correctly (200 OK)
  • window.DotNet is available
  • Application loads without JavaScript errors
  • Blazor WebAssembly framework works correctly

🧪 Testing (testing in Macbook Pro m2)

  1. Run dotnet restore on the project
  2. Run dotnet build - should compile without errors
  3. Run dotnet run - server should start correctly
  4. Navigate to http://localhost:5000 - application should load without console errors

📁 Files Modified

  • src/NPacMan.Blazor/NPacMan.Blazor.csproj - SDK change

🎯 Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

✔️ Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have tested that my changes work correctly
  • My changes generate no new warnings or errors

- Changed SDK from Microsoft.NET.Sdk.Web to Microsoft.NET.Sdk.BlazorWebAssembly
- Resolves 404 errors for blazor.webassembly.js
- Fixes JavaScript errors related to window.DotNet not being available
- Enables proper Blazor WebAssembly framework file generation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants