"Failed to get roles" in page properties

I used the "Blazor CRM app" to create a new project. The application runs fine (after fixing an "AddInteractiveServerRenderMode" error in the generated code). However, when I open a page in Blazor Studio, I a "Failed to get roles" message in page properties. How do I address this issue?

I've just used the latest version to create new CRM app using the template (Blazor server) however didn't received such error. Can you post additional info on how to reproduce this?


I've managed to reproduce this however - it's caused by the additional partial class in the page (there is similar in other security pages since we share code between out templates). To fix it move the SecurityService declaration inside the main class and delete the additional partial class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Radzen;
using Radzen.Blazor;

namespace CRMNew.Components.Pages
{
    public partial class AddApplicationRole
    {
        [Inject]
        protected IJSRuntime JSRuntime { get; set; }

        [Inject]
        protected NavigationManager NavigationManager { get; set; }

        [Inject]
        protected DialogService DialogService { get; set; }

        [Inject]
        protected TooltipService TooltipService { get; set; }

        [Inject]
        protected ContextMenuService ContextMenuService { get; set; }

        [Inject]
        protected NotificationService NotificationService { get; set; }

        [Inject]
        protected SecurityService Security { get; set; }

        protected CRMNew.Models.ApplicationRole role;
        protected string error;
        protected bool errorVisible;

        protected override async Task OnInitializedAsync()
        {
            role = new CRMNew.Models.ApplicationRole();
        }

        protected async Task FormSubmit(CRMNew.Models.ApplicationRole role)
        {
            try
            {
                await Security.CreateRole(role);

                DialogService.Close(null);
            }
            catch (Exception ex)
            {
                errorVisible = true;
                error = ex.Message;
            }
        }

        protected async Task CancelClick()
        {
            DialogService.Close(null);
        }
    }
}

We will fix our template in our next update.

Regarding the InteractiveServerRenderMode():

  • Create a CRM Blazor app with Interactivity = Auto. (I used SQLite, but suspect that doesn't matter.)
  • Run the app and see error in web browser. (The error description is helpful.)
  • Add a line to the server project's Program.cs file as shown below.
app.MapRazorComponents<App>()
   .AddInteractiveWebAssemblyRenderMode()
   .AddInteractiveServerRenderMode() // ADD THIS LINE
   .AddAdditionalAssemblies(typeof(TestApp.Client._Imports).Assembly);

Run the app again and all is well.

Thanks! We will update our template.

@enchev: While your advice addressed my page rendering issue (thank you), it did not address my "Failed to get roles" issue. See highlighted content in the image below. I welcome any advice.

Getting this error means that Radzen Blazor Studio cannot connect to your database for some reason. Unfortunately this isn't easy to troubleshoot as it depends a lot on the database settings and connection string.

Your response gave me an idea, which solved my problem. Keep in mind that my context is the CRM Blazor app using SQLite.

Update the connection string in appSettings.Development.json from this generated content with a relative path:

"ConnectionStrings": {
    "CrmDBConnection": "Data Source=./Data/data.db"
},

to a full path, which for my example is:

"ConnectionStrings": {
    "CrmDBConnection": "Data Source=/Users/jw/Repos/crm-auto-test/Server/Data/data.db"
},

By the way, using Data Source=~/Repos/crm-auto-test/Server/Data/data.db did not work. (i.e., using the tilde character for /Users/jw)