Open Closed

Maui Blazor (Hybrid) App - Mobile Application Won't Start Without .HttpApi.Host project Running #7970


User avatar
0
DWaterfield created
  • Template: app
  • Created ABP Studio Version: 0.8.2
  • Tiered: No
  • UI Framework: maui-blazor
  • Theme: leptonx
  • Theme Style: system
  • Database Provider: ef
  • Database Management System: sqlserver
  • Separate Tenant Schema: No
  • Mobile Framework: maui
  • Public Website: No
  • Optional Modules:
    • GDPR
    • FileManagement
    • TextTemplateManagement
    • LanguageManagement
    • AuditLogging
    • SaaS
    • OpenIddictAdmin
  • Exception message and full stack trace:

  • Steps to reproduce the issue: We're using the default MAU Blazor (Hybrid) template as created via ABP Studio, and have added the "Login workaround" code as provided here [Maui Blazor (Hybrid) App Can't Login #7908](https://abp.io/support/questions/7908/Maui-Blazor-Hybrid-App-Can%27t-Login)

The solution name is Handheld When the "Server" project Handheld.HttpApi.Host is running and the mobile app Handheld.MauiBlazor is deployed and running on an Android emulator, all works as expected, however when the "Server" project is not running (to simulate the mobile device not having connectivity to the server), the mobile app Handheld.MauiBlazor does not start and throws the above exception in MauiProgram.cs

The reason we're testing this is that the mobile application needs to be able to work when it has no Internet Connectivity as it will be used to take photos as part of vehicle inspections, some of which take place at airfields or ports where Internet connectivity is not always available.

While we realise that none of the "Server" functionality would be accessible via the APIs in the Handheld.HttpApi.Host, we were hoping to be able to test for Network Connectivity using the normal MAUI libraries e.g. Connectivity and switch functionality on/off as appropriate.

The client project (Handheld.MauiBlazor) that is deployed to the mobile device though, appears to perform a lot of calls to the server as part of its "startup code".

Q. As a mobile app that won't start unless it has full internet connectivity is not going to be practicable for us, how might we utilise the ABP Studio MAUI (Blazor Hybrid) template / libraries to achieve this?


16 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi,

    You told you are working on Android. Did you forward your local machine port to the emulator by following Port mapping step from the documentation?

    https://abp.io/docs/latest/framework/ui/maui?Tiered=No#android

    As an example:

    adb reverse tcp:44305 tcp:44305
    

    44305 should be your HttpApi.Host port

  • User Avatar
    0
    DWaterfield created

    Hi,

    Yes we did the adb step, which in our case is

    adb reverse tcp:44358 tcp:44358
    

    I didn't write down each specific step as in our previous question Login question in order to keep the question clear, but it is the same Solution.

    I mentioned that we have liangshiwei's workaround code in place in case it is relevant, but the startup behaviour is the same without that workaround code in place.

    With the server project (Handheld.HttpApi.Host) running we have a functioning app and we can even Login due to the workaround code.

    When the server project is running......... If we put a breakpoint on line 36 (see screenshot in the question) and then execute that line, we see the following in the console output window of the server (Handheld.HttpApi.Host) project

    The red outlined section is what happens as line 36 is executed, with the yellow section appearing to show calls to the server e.g.

    [INF] Request finished HTTP/1.1 GET https://localhost:44358/api/abp/application-configuration?IncludeLocalizationResources=False&api-version=1.0 - 200 null application/json; charset=utf-8 75.7252ms 2024-09-26 10:56:15.896 +01:00 [INF] Request starting HTTP/1.1 GET https://localhost:44358/api/abp/application-localization?CultureName=en&OnlyDynamics=True&api-version=1.0 - null null

    which is why we suspect that when the deployed mobile project (Handheld.MauiBlazor) cannot contact the server (as might be the case for a mobile application), these calls fail and the application cannot startup?

  • User Avatar
    0
    improwise created

    Unless things have changed very recently, we can confirm seeing the same problem, app would not run without the backend available. In our case, that was not a problem so we never bothered to investigate it further. This is true also with the app deployed to my Android with the backend i Azure stopped.

  • User Avatar
    0
    DWaterfield created

    Thank you for the confirmation.

    While we understand that the abp libraries both open source and commercial should be platform agnostic and shouldn't have to care about high level issues like connectivity, it seems like unfortunately, the "disconnected scenario" has not been considered for the overall ABP Maui Blazor Hybrid project template?

    Which leaves us in a tricky situation as we seemingly can't use ABP to create the mobile client of our Application?

    Q. Could we please get a view from the ABP Architect/Designers whether that is the actual current situation and whether/if the ABP templates are likely to deal with the disconnected scenario in the near future?

    If that isn't likely to happen in the very near future or not at all, then we still have a project to start which leaves us with the option of using the Microsoft projects templates i.e. for the mobile part, and getting some use out of the ABP Product by utilising the ABP server side parts.

    Q. Presumably we could call all the existing ABP endpoints that we see via Swagger on the Handheld.HttpApi.Host project and get some use from the ABP libraries?

    We're not sure if that means removing these parts from the Solution

    or... Q. whether it would be cleaner to just create an ABP Blazor Server App so we'd still have our GUI for administering Users, setting up Tenants, viewing Audit Logs etc. and call into the nnnnHttpApi.Host via the Swagger endpoints from a Visual Studio generated ".NET MAUI Blazor Hybrid and Web App" which would startup in the disconnected state and we could also detect when we have connectivity and call our server side logic through the abp/api endpoints when required?

  • User Avatar
    0
    improwise created

    Honestly, not due to ABP but we have given up on MAUI for now even tough we are .NET people. Would really like to use it though if/once it becomes ready for prime time including tooling that does not break as soon as you try to install Firebase packages etc. The dream to finally get rid of JS continues to be a dream but one day :)

    But that is probably another discussion, but that is the main reason we did not continue trying to get it to work properly with ABP. I hope you manage to get it sorted for your needs.

  • User Avatar
    0
    DWaterfield created

    Honestly, not due to ABP but we have given up on MAUI for now even tough we are .NET people. Would really like to use it though if/once it becomes ready for prime time including tooling that does not break as soon as you try to install Firebase packages etc. The dream to finally get rid of JS continues to be a dream but one day :)

    But that is probably another discussion, but that is the main reason we did not continue trying to get it to work properly with ABP. I hope you manage to get it sorted for your needs.

    Thanks for the heads up, we've had great success with Blazor Server and the ABP libraries that utilise that architecture, with the rapid development due to not having to duplicate all dto's in C# and javascript and the magic SignalR connection between server and browser, but our mobile journey is just beginning.

    We seem to have hit a very large brick wall at the moment, and we really want to utilise HTML, CSS and razor pages rather than .XAML......but we shall have to see how this all ends up!

  • User Avatar
    0
    improwise created

    Honestly, not due to ABP but we have given up on MAUI for now even tough we are .NET people. Would really like to use it though if/once it becomes ready for prime time including tooling that does not break as soon as you try to install Firebase packages etc. The dream to finally get rid of JS continues to be a dream but one day :)

    But that is probably another discussion, but that is the main reason we did not continue trying to get it to work properly with ABP. I hope you manage to get it sorted for your needs.

    Thanks for the heads up, we've had great success with Blazor Server and the ABP libraries that utilise that architecture, with the rapid development due to not having to duplicate all dto's in C# and javascript and the magic SignalR connection between server and browser, but our mobile journey is just beginning.

    We seem to have hit a very large brick wall at the moment, and we really want to utilise HTML, CSS and razor pages rather than .XAML......but we shall have to see how this all ends up!

    Xamarin Forms AFAIK is EOF now so it's all MAUI. Don't think that neither ABP nor Blazor is the main problem here for the time being. Would be really nice to be able to reuse Blazor though all the way.

  • User Avatar
    0
    DWaterfield created

    ... Xamarin Forms AFAIK is EOF now so it's all MAUI. Don't think that neither ABP nor Blazor is the main problem here for the time being. Would be really nice to be able to reuse Blazor though all the way.

    We agree, .Net MAUI has replaced Xamarin.

    We're interested in the MAUI Blazor Hybrid model (which our understanding is that its a Blazor webview control running natively inside a mobile device under .Net MAUI) because it lets us utilise our decades of HTML, .css etc. knowledge rather than having to use .XAML which came in with Silverlight / WPF IIRC, and we can still access the mobile hardware such as the camera etc. while developing in C#

    Our immediate roadblock is that its looking like the ABP template was not designed to work in the scenario where the mobile device does not have 100% connectivity!

    We'll have to see what the ABP architects/designers say re my questions to decide what direction / solution we end up with!

  • User Avatar
    0
    DWaterfield created

    Can we have a response from ABP Support Team please?

    Thank you.

  • User Avatar
    0
    DWaterfield created

    @enisn A disappointing lack of support from ABP..............

    Let me ask the question in a more concise way based upon what we have deduced the past week while we've been waiting for a reply............

    We've concluded the ABP .Net Maui Blazor Hybrid template will not work if the mobile device does not enjoy 100% connectivity at all times, which is unrealistic for a mobile device.

    What we really need is the following

    i.e. a Blazor Server App, with .Net Maui Hybrid project(s) forming the Mobile Framework part.

    That will give us a server application with all the usual menus for Administering users/config, viewing Audit Logs etc. and a mobile part that can be deployed to devices.

    We're trying to construct this ourselves i.e.

    where the highlighted projects were created by the Visual Studio template

    Q. with regard to authentication, can we just call the Swagger Login endpoint on the server to authenticate, or do we need to do anything else?

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Q. with regard to authentication, can we just call the Swagger Login endpoint on the server to authenticate, or do we need to do anything else?

    You can use the same way with MauiBlazor template. It has pre-configured login-flow by using Volo.Abp.Account.Pro.Public.MauiBlazor package. You can check usage of by creating a MauiBlazor template and implement to your case.

    Alternatively, you can implement OAUTH login from scratch by using WebAuthenticator

  • User Avatar
    0
    DWaterfield created

    Edit: ...........

    We have found the source for Volo.Abp.Account.Pro.Public.MauiBlazor within the Pro Account module.

    Q. Are saying we can somehow utilise this package in the Microsoft Maui Blazor Hybrid project to implement a Login flow? It seems pretty tightly coupled to the ABP architecture.

    Q. Also can you please comment on why the ABP Maui Blazor Hybrid will not startup without connectivity to the Server as we haven't received an answer to our overall question. If we could resolve that we wouldn't have to try and roll our own Maui Blazor Hybrid Client

  • User Avatar
    0
    DWaterfield created

    Another 5 days have gone by with no response, and 13 days since our initial question, which remains unanswered. Can someone in support please assist with this question?

    I'll repeat it here for clarity

    Q. Also can you please comment on why the ABP Maui Blazor Hybrid template will not startup without connectivity to the Server?

    If any further information is required then please let us know.

    Thank you.

  • User Avatar
    0
    DWaterfield created

    It appears that no one is dealing with this support ticket?

    We will email ABP Support directly as we need to know if this behaviour is a bug or by design so we can decide which direction we go in with regard to creating our own Maui Blazor Hybrid Client with an ABP Backend or whether we have to abandon our use of ABP for this project.

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Q. Are saying we can somehow utilise this package in the Microsoft Maui Blazor Hybrid project to implement a Login flow? It seems pretty tightly coupled to the ABP architecture.

    Yes it's built for the best compatibility with ABP and ABP services. If you need the same implementation for plain Blazor Hybrid project, you'll need to implement it yourself, this package can't be used without ABP.

    Also can you please comment on why the ABP Maui Blazor Hybrid will not startup without connectivity to the Server as we haven't received an answer to our overall question.

    ABP Client architecture is designed for Web Applications mostly MVC & Blazor, so they need to get configuration from server. By default ABP applications can't work without a backend, since they get application-configuration, permissions and even localization from backend. But you can still handle Application Initialization in MauiProgram.cs with a simple try-catch code block and show a different error page when there is no connection. Or you can override client packages to cache application-configuration and other datas from server.

    the following code in MauiProgram.cs sends request to backend, gets configuration and initializes all the ABP infrastructure: csharp app.Services.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(app.Services);

  • User Avatar
    0
    DWaterfield created

    Thanks for the response enisn,

    We've decided to go with your suggestion of examining the source for Volo.Abp.Account.Pro.Public.MauiBlazor and implementing that in our app so we can use the same Authorization code flow as recommended in the OAuth spec.

    We've included that code in a Visual Studio generated "Maui Blazor Hybrid" project which will be our client app and we now have a working Login / Authentication / Authorization flow with an Authenticated User and we can use the usual [Authorize] attributes and @if(User.IsAuthenticated) { ... } in razor pages.

    For the server we'll be creating an app via ABP Studio using the new "Blazor WebApp" template. We already have our client app talking to a current "Blazor Server" app backend, so we anticipate it will all work ok.

    That way we can have the server back end with all the usual Admin menus to allow us to setup Users, View Audit Logs, configure OIDC Applications and generate backend Application Services using ABP in the normal way.

    So I think what we're creating is essentially the screenshot I posted earlier in this thread i.e. a Blazor backend with Maui Blazor Hybrid as the mobile framework part.

    Whether the current MAUI or React Native also require a backend to start we don't know as its the missing Blazor Hybrid (but with the ability to start without internet connectivity) that we're interested in.

    Perhaps Volosoft/ABP can consider that as a feature request, or allow the current Maui Blazor Hybrid app to cache what it needs from the server in some fashion when it has no connectivity?

    Thank you.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35