I have a solution with multiple .NET 8 Blazor projects, including a class library used to share common code.
Solution
- Project 1
- Project 2
- SharedLibrary
Now I’d like to share Blazor dialogs. My Blazor projects use MudBlazor for UI. For some reason, this doesn’t work:
- Dialog is in
Project 1
–> Dialog can be reused withinProject 1
, notProject 2
- Dialog is in
Project 2
–> Dialog can be reused withinProject 2
, notProject 1
- Dialog is in
SharedLibrary
–> Dialog cannot be used by any Blazor project.
My IDE doesn’t show any warnings until the code is compiled. I get this error:
Error CS0246 : The type or namespace name ‘CreateNewFolder’ could not be found (are you missing a using directive or an assembly reference?)
Both Project 1
and Project 2
reference the project SharedLibrary
and I do have a using statement on the top of the Navigation menu, where the dialog is supposed to be called from:
@using SharedLibrary.Shared
This method is calling the dialog:
private void ShowNewFolder(MouseEventArgs _obj)
{
ShowNewFolderDialog = true;
var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Medium };
DialogService.ShowAsync<CreateNewFolder>("Create New Folder", options);
}
I tried finding relevant question but cannot find anybody having the same issue. Most like I’m missing something very basic.
Would somebody please be so kind to explain what I’m supposed to do so I can share dialogs across projects?
2
as mentioned by @Jilael, the solution was to add a Razor Class Library
to share UI code within the solution