Starts in:
2 DAYS
4 HRS
51 MIN
16 SEC
Starts in:
2 D
4 H
51 M
16 S
Open Closed

maui-blazor Template throws Exception on first run. #4625


User avatar
0
joerguth created
  • ABP Framework version: v7.1.0-rc.2
  • UI type: MauiBlazor
  • DB provider: EF Core
  • Tiered: yes
  • Exception message and stack trace: Volo.Abp.AbpInitializationException: "An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Volo.Abp.AspNetCore.Components.MauiBlazor.AbpAspNetCoreComponentsMauiBlazorModule, Volo.Abp.AspNetCore.Components.MauiBlazor, Version=7.0.2.0, Culture=neutral, PublicKeyToken=null: An error occurred during the ABP remote HTTP request. (Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte. (localhost:44300)) See the inner exception for details.. See the inner exception for details." Stacktrace: bei Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context) bei Volo.Abp.AbpApplicationBase.InitializeModules() bei Volo.Abp.AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider) bei xxx.MauiBlazor.App.InitializeAbpApplication(IAbpApplicationWithExternalServiceProvider abpApplication, IServiceProvider serviceProvider) in D:\DEV\src\xxxxx.MauiBlazor\App.xaml.cs: Zeile21

InnerException Source Volo.Abp.Http.Client

  • Steps to reproduce the issue:"

I created a new application with the cli version 7.1.0-rc.2 and did not make any changes. abp new DemoApp -t app-pro -u maui-blazor --separate-auth-server --with-public-website --no-random-port

After running DbMigrator, the AuthServer, HttpApi.Host and MauiBlazor were started. The MauiBlazor application started but an exception occurs in App.xaml.cs => InitializeAbpApplication.

v7.1.0-rc.2 App.xaml.cs

public App(
        IAbpApplicationWithExternalServiceProvider abpApplication,
        IServiceProvider serviceProvider)
    { 
        InitializeComponent();
        InitializeAbpApplication(abpApplication, serviceProvider);
    }

private void InitializeAbpApplication(IAbpApplicationWithExternalServiceProvider abpApplication, IServiceProvider serviceProvider)
    {
        try
        {
            abpApplication.Initialize(serviceProvider);
            MainPage = new MainPage();
        }
        catch (AbpInitializationException ex)
        {
#if DEBUG
            MainPage = GetErrorPage(ex.Message);
#else
            MainPage = GetErrorPage("Application couldn't be initialized.");
#endif
        }
    }

v7.0.2 App.xaml.cs

public App()
    {
        InitializeComponent();

        MainPage = new MainPage();
    }

In the template of Version 7.0.1 there was no start problem, the Source of MauiProgram.cs includes this additional lines:

 public static MauiApp CreateMauiApp()
{
// snip    
var app = builder.Build();
app.Services.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(app.Services);
return app;
}

8 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    A connection could not be established because the target computer refused the connection

    Hi,

    Did you start the backend (Authserver & HttpAPI.Host)?

  • User Avatar
    0
    joerguth created

    Hi, yes i did.

  • User Avatar
    1
    joerguth created

    @liangshiwei meanwhile I have made the following changes: Reverted following code from template version 7.0.1, this works so far.

    For what reason the template was changed?

    App.xaml.cs ctor without calling InitializeAbpApplication

    public App(
            IAbpApplicationWithExternalServiceProvider abpApplication,
            IServiceProvider serviceProvider)
        {
            InitializeComponent();
            // JU Workaround
             // InitializeAbpApplication(abpApplication, serviceProvider);
            MainPage = new MainPage();
        }
    

    MauiProgram.cs

    public static MauiApp CreateMauiApp()
    {
     // snip
    // JU Workaround
            // return builder.Build();
            var app = builder.Build();
            app.Services.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(app.Services);
            return app;
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    If an exception occurs in the remote service:

    Old way The application won't start and you can't see the exception

    New way The application will startup and you can see the exception.

    It seems a problem, we will check it.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    We will revert this change and try to find a better way.

  • User Avatar
    0
    joerguth created

    Maybe this can help:

    private async Task<bool> IsRemoteServiceUp(IAbpApplicationWithExternalServiceProvider abpApplication) 
        {
            var configuration = abpApplication.Services.GetConfiguration();
            var remoteServiceUri = configuration["RemoteServices:Default:BaseUrl"];
    
            if (remoteServiceUri == null)
            { 
                return false; 
            }
            var ping = new System.Net.NetworkInformation.Ping();
            var host = new Uri(remoteServiceUri).Host;
    
            var reply = await ping.SendPingAsync(host);
    
            return reply.Status == System.Net.NetworkInformation.IPStatus.Success;
        }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Thanks, we will consider this.

  • User Avatar
    0
    joerguth created

    Sorry for posting this Ping Example it didnt work because it only works with the host without the ports. I am seeing two ways: 1.) with new System.Net.Sockets.TcpClient(); 2 ) with AddHttpClient and using Polly with AddTransientHttpErrorPolicy and AddPolicyHandler

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06