Loading MudBlazor components dynamically at runtime in .NET MAUI

Loading MudBlazor components dynamically at runtime in .NET MAUI

12 November 2025

Buy Me A Coffee

Hello! Today we will talk about a challenge that often arises when building enterprise-grade modular systems: Loading MudBlazor components dynamically at runtime in .NET MAUI.

In a standard .NET MAUI Hybrid application, your Razor components are compiled into the main assembly. But what if you need to build a "Plug-and-Play" architecture where a server can send a .dll containing new UI views, and your app renders them without a trip to the App Store? This is particularly useful for dashboards, dynamic forms, or white-labeling.

The Challenge: Why Reflection isn't enough

Loading an assembly via Assembly.Load is the easy part. The real difficulty in a Blazor Hybrid environment is that the RenderTree needs to know about the new components, and more importantly, MudBlazor services (like the DialogService or Snackbar) must be correctly injected into these external components.

1. Preparing the Plugin (The Razor Class Library)

Your plugin must be a Razor Class Library (RCL). To keep it compatible with MudBlazor, ensure it references the same version of the library as your host app.

2. Loading the Assembly via AssemblyLoadContext

To avoid memory leaks and allow for potential unloading, we use a custom AssemblyLoadContext.

3. Registering the Dynamic Component in the RenderTree

The "magic" happens in your Blazor page. Instead of a static component tag, we use the <DynamicComponent /> provided by ASP.NET Core.

4. Handling Dependency Injection

For MudBlazor components to work inside the dynamic DLL, they must share the same IServiceProvider instance. Since DynamicComponent uses the host’s container, your DialogService and SnackbarProvider will work out of the box, provided you have the <MudThemeProvider /> and providers initialized in your MainLayout.razor.

Summary

By combining AssemblyLoadContext and <DynamicComponent />, you can transform your .NET MAUI app into a flexible shell. This approach solves the problem of rigid UI structures and allows your MudBlazor interfaces to evolve independently of the core application logic.

Have you tried loading external assemblies in MAUI? Let’s discuss the potential pitfalls in the comments!

Buy Me A Coffee

Related:

Extend .NET MAUI application with iOS Extensions

Extend the .NET MAUI application with iOS App Extension in 5 steps.

Converting Word documents to PDF on mobile devices

Explore the performance and challenges of converting Word documents to PDF on mobile devices using .NET MAUI, comparing libraries like Aspose.Words, Syncfusion DocIO, and Spire.Doc.

An unhandled error has occurred. Reload

🗙