Matblazor: MatHttpClientExtension has conflict with Microsoft.AspNetCore.Components.HttpClientJsonExtensions

Created on 4 Jun 2020  Â·  7Comments  Â·  Source: SamProf/MatBlazor

Describe the bug
Extension collision with Microsoft library: Microsoft.AspNetCore.Blazor.HttpClient.GetJsonAsync
When calling GetJsonAsync, will cause build error ambiguous with Microsoft.AspNetCore.Components.HttpClientJsonExtensions

One workaround is just use the new library from Microsoft...

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Blazorfiddle link
Please provide a mock implementation of your code on www.blazorfiddle.com - this makes it a lot easier for us and you can get faster feedback on your issue 😉
Hit save and post the URL under this header.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots or .GIF captures to help explain your problem

Additional context
Add any other context about the problem here.

bug

Most helpful comment

According to blazor wasm preview 3 release note:

extension methods are now available in preview with the System.Net.Http.Json package and they will replace the existing helper methods in the Microsoft.AspNetCore.Blazor.HttpClient package

The old one will have conflict.
The new ones have different name. Old ones:Microsoft.AspNetCore.Blazor.HttpClient
GetJsonAsync

New lib System.Net.Http.Json
GetFromJsonAsync

Still though... Not sure why matBlazor needs to define own GetJsonAsync

All 7 comments

Can you please describe the workaround more thoroughly? You mention to 'just use the new library from Microsoft"... which library are you talking about?

According to blazor wasm preview 3 release note:

extension methods are now available in preview with the System.Net.Http.Json package and they will replace the existing helper methods in the Microsoft.AspNetCore.Blazor.HttpClient package

The old one will have conflict.
The new ones have different name. Old ones:Microsoft.AspNetCore.Blazor.HttpClient
GetJsonAsync

New lib System.Net.Http.Json
GetFromJsonAsync

Still though... Not sure why matBlazor needs to define own GetJsonAsync

Currently this bug breaks all .net5 builds.

DepartmantShow.razor(40, 37): [CS0121] The call is ambiguous between the following methods or properties: 'Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync<T>(System.Net.Http.HttpClient, string)' and 'MatBlazor.MatHttpClientExtension.GetJsonAsync<T>(System.Net.Http.HttpClient, string)'

Cause:
https://github.com/SamProf/MatBlazor/blob/41cbda732c38ece77554cac436c548c2edc18b12/src/MatBlazor/Helpers/MatHttpClientExtension.cs

Can you please remove this if not needed or rename it to not conflict with the blazor framework?

Currently this bug breaks all .net5 builds.

DepartmantShow.razor(40, 37): [CS0121] The call is ambiguous between the following methods or properties: 'Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync<T>(System.Net.Http.HttpClient, string)' and 'MatBlazor.MatHttpClientExtension.GetJsonAsync<T>(System.Net.Http.HttpClient, string)'

Cause:
https://github.com/SamProf/MatBlazor/blob/41cbda732c38ece77554cac436c548c2edc18b12/src/MatBlazor/Helpers/MatHttpClientExtension.cs

Can you please remove this if not needed or rename it to not conflict with the blazor framework?

i agree with you

Can you please describe the workaround more thoroughly? You mention to 'just use the new library from Microsoft"... which library are you talking about?

my workaround : downgate matblazor to 2.4.3

'Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync’ is the msft lib

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: seebosmilenotifications@github.com
Sent: Friday, August 7, 2020 4:21 PM
To: SamProf/MatBlazorMatBlazor@noreply.github.com
Cc: Alienroidiam31337@hotmail.com; Authorauthor@noreply.github.com
Subject: Re: [SamProf/MatBlazor] MatHttpClientExtension has conflict with Microsoft.AspNetCore.Components.HttpClientJsonExtensions (#595)

Currently this bug breaks all .net5 builds.

DepartmantShow.razor(40, 37): [CS0121] The call is ambiguous between the following methods or properties: 'Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync(System.Net.Http.HttpClient, string)' and 'MatBlazor.MatHttpClientExtension.GetJsonAsync(System.Net.Http.HttpClient, string)'

Cause:
https://github.com/SamProf/MatBlazor/blob/41cbda732c38ece77554cac436c548c2edc18b12/src/MatBlazor/Helpers/MatHttpClientExtension.cs

Can you please remove this if not needed or rename it to not conflict with the blazor framework?

i agree with you

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com/SamProf/MatBlazor/issues/595#issuecomment-670781171, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH3FBMUQFFVEASQYXZWISATR7SD6FANCNFSM4NS6THLQ.

I have a workaround for this "The call is ambiguous" problem:

First, I have created a new static class, named HttpClientHelper, adding the following code:

using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace MyProject.WebGui
{
    public static class HttpClientHelper
    {
        public static Task<T> GetJSONAsync<T>(this System.Net.Http.HttpClient client, string url)
        {
            return client.GetJsonAsync<T>(requestUri: url);
        }
    }
}

Then I iterated through the project's Error List to find the _GetJsonAsync_ references and replaced them with _GetJSONAsync_. For example:

firma = await HttpClient.GetJSONAsync<Firma>(url.ToString());

Now I'm able to use 2.7.0.
Cheers

Was this page helpful?
0 / 5 - 0 ratings