Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Exception when using .SetLocaleAsync with LocaleResource in MAUI #578

Open
thirstyape opened this issue Feb 7, 2025 · 4 comments · Fixed by #579
Open

Bug: Exception when using .SetLocaleAsync with LocaleResource in MAUI #578

thirstyape opened this issue Feb 7, 2025 · 4 comments · Fixed by #579

Comments

@thirstyape
Copy link
Contributor

thirstyape commented Feb 7, 2025

Very simple error here, simply put MAUI does not support reading content via HttpClient; using something like FileSystem will work. Going to get a PR out for this in an hour or two but you'll need to let me know what you think. My plan is to do the following:

  • Add a new project for MAUI (Blazor-ApexCharts-MAUI)
  • Add an implementation of IApexChartService
  • Add an extension such as public static IServiceCollection AddApexChartsMaui

Here is the code to produce.

protected async override Task OnInitializedAsync() 
{
    var frenchCL = new ChartLocale
    {
	Name = "fr",
	Options = new LocaleOptions()
    };

    var frenchLR = new LocaleResource
    {
	Name = "fr",
	Language = "French"
    };

    ChartOptions.Chart.Locales = new List<ChartLocale> { frenchCL };

    try
    {
	await ApexChartService.SetLocaleAsync(frenchLR, false);

	if (ChartReference != null)
		await ChartReference.SetLocaleAsync("fr");
    }
    catch (Exception ex)
    {
	Logger.LogError("Error while setting locale. {type} {message}", ex.GetType().Name, ex.Message);
	Logger.LogError("{trace}", ex.StackTrace);
    }
}

For reference, here is the error from MAUI logs.

Error while setting locale. 
HttpRequestException 
IPv4 address 0.0.0.0 and IPv6 address ::0 are unspecified addresses that cannot be used as a target address. (Parameter 'hostName') (0.0.0.0:443)

at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem) at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter`1.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, Boolean async, CancellationToken requestCancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendCoreAsync>g__Core\|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core\|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken) at System.Net.Http.HttpClient.<SendAsync>g__Core\|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at System.Net.Http.Json.HttpClientJsonExtensions.<FromJsonAsyncCore>g__Core\|12_0[TValue,TJsonOptions](HttpClient client, Task`1 responseTask, Boolean usingResponseHeadersRead, CancellationTokenSource linkedCTS, Func`4 deserializeMethod, TJsonOptions jsonOptions, CancellationToken cancellationToken) at ApexCharts.ApexChartService.SetLocaleAsync(LocaleResource localeResource, Boolean reRenderCharts) at my.Component.OnInitializedAsync()
@thirstyape
Copy link
Contributor Author

thirstyape commented Feb 7, 2025

Ok, PR is out. I needed to change some internal stuff to public. If this is not desirable an alternative would be to abstract the HttpClient stuff into something like IContentReader and replace stuff in the main class.

Will need an updated or secondary .yml for build. Let me know about any changes needed.

@joadan joadan reopened this Feb 11, 2025
@joadan
Copy link
Member

joadan commented Feb 11, 2025

Hi, I accepted the PR but I realize that I probably misunderstood the issue a bit.

I understand that in MAUI it is not possible to use the httpClient in the chart service.
So we need a implementation that can work with local file system, correct.
But do we need a dependacy on MAUI?

Sorry if I'm missing something obvious here.

@thirstyape
Copy link
Contributor Author

Yes, the local filesystem is the way to go. As far as I know this needs to be done by FileSystem.Current.OpenAppPackageFileAsync() to access the wwwroot folder. Where FileSystem is part of the Microsoft.Maui.Storage namespace.

This is why I placed it into a separate project, so there are no new dependencies on the main package. Then the release.yml file could be updated to create a secondary package which would be the recommended package for anyone running MAUI as it will contain the main one as well.

I can do another PR for the changes to the script but it should be pretty easy. Just add the dotnet workload install maui and a second dotnet pack -c Release -p:Version=${GITHUB_REF##*/v} for that project. Will likely need to be a second script or job in the current script as I was unable to get the MAUI workloads to install on Ubuntu.

@joadan
Copy link
Member

joadan commented Feb 15, 2025

Thank you, makes sense.

Let me get back you on the changes for the nuget script. I will now remove support for .NET 6 and .NET 7 and add support .NET 9.
That will make changes to all scripts. This is not my strong side so any help is much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants