Jump to content

[C# Blazor] Blazor does not support package:// protocol


Recommended Posts

I've heard many times that it is possible to use Blazor for the UI, but I'm struggling to get it working.

I'm trying to create a Blazor WebAssembly app and run it under CEF. From what I see during the initialization Blazor tries to fetch a configuration file blazor.boot.json and to do that it uses the same URL root as the one that is currently running in CEF. However the fetch operation does not support the package:// protocol that is used when the browser window is created and this results in the following error:

blazor.webassembly.js:1 Fetch API cannot load package://package_name/wwwroot/_framework/blazor.boot.json. URL scheme "package" is not supported.
(anonymous) @ blazor.webassembly.js:1
blazor.webassembly.js:1 TypeError: Failed to fetch
    at Function.<anonymous> (blazor.webassembly.js:1)
    at blazor.webassembly.js:1
    at Object.next (blazor.webassembly.js:1)
    at blazor.webassembly.js:1
    at new Promise (<anonymous>)
    at blazor.webassembly.js:1
    at Function.initAsync (blazor.webassembly.js:1)
    at blazor.webassembly.js:1
    at blazor.webassembly.js:1
    at Object.next (blazor.webassembly.js:1)

Is there any workaround for this issue? Is Blazor actually supported?

Link to comment
Share on other sites

  • 5 months later...


Finally, I found a solution for this problem.

You have two options, both requires hosting a server for client-side files:

  1. Use Blazor Server
    Blazor Server is the perfect solution, because you can easily share data between connections (clients/players). The biggest disadvantage is performance. If your UI use events like OnMouseMove, you are in trouble, because of network delay. 
  2. Use Blazor WebAssembly
    This is tricky. You can't just copy published files to client_packages, because Blazor don't support non-http protocols (package://). You have to publish your Blazor app on dedicated server and "redirect" client to your app.

If you would like to connect your Blazor app directly to RageMP server, you can do that using SignalR.

.NET 6.0 for now doesn't work. Use .NET 5.0 instead.

I tested it on my local PC with IIS installed. It should work with Apache, but I can't confirm this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...