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

Kiota C# Client crashes on Blazor WASM #481

Open
brad-technologik opened this issue Nov 21, 2024 · 7 comments
Open

Kiota C# Client crashes on Blazor WASM #481

brad-technologik opened this issue Nov 21, 2024 · 7 comments
Labels
status:needs-more-information An issue that requires additional information from issue author status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question

Comments

@brad-technologik
Copy link

brad-technologik commented Nov 21, 2024

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

When I try and import my Kiota C# in a Blazor WASM Project, the page gets an error whenever the Kiota client is injected into a page:

ManagedError: One or more errors occurred. (Operation is not supported on this platform.)

Expected behavior

Kiota C# client should work in Blazor. The error is kind of vague, but it may be related to multi threading which isn't supported in Blazor.

Given how Kiota and Blazor are both Microsoft products, I'd expect them work together.

How to reproduce

dotnet new blazor -ai -int WebAssembly -n KiotaBlazorBug
cd KiotaBlazorBug/KiotaBlazorBug.Client
dotnet add package Microsoft.Kiota.Bundle
kiota generate --language=CSharp -d https://petstore3.swagger.io/api/v3/openapi.json -o ./Client -c PetStoreClient -n KiotaBlazorBug.Client

Add the following code to Program.cs (In both KiotaBlazorBug/KiotaBlazorBug/Program.cs and KiotaBlazorBug/KiotaBlazorBug.Client)

builder.Services.AddSingleton<PetStoreClient>(e =>
{
    var authProvider = new AnonymousAuthenticationProvider();
    // Create request adapter using the HttpClient-based implementation
    var adapter = new HttpClientRequestAdapter(authProvider);
    // Create the API client
    return new PetStoreClient(adapter);
});

Add the following line to Counter.razor

@inject PetStoreClient PetStoreClient

Run the project

cd ../KiotaBlazorBug
dotnet run

Visit http://localhost:5003/counter in your Browser and observe the error and JS console.

Open API description file

Any one. https://petstore3.swagger.io/api/v3/openapi.json is an example.

Kiota Version

1.20.0+81bdb1bf13383a749f794d47926d09733d2d7be1

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

  • OS: Mac OS 15.1 (24B83)

Debug output

Click to expand log ``` blazor.web.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Operation is not supported on this platform. System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Net.Http.SocketsHttpHandler.set_Proxy(IWebProxy value) at Microsoft.Kiota.Http.HttpClientLibrary.KiotaClientFactory.GetDefaultHttpMessageHandler(IWebProxy proxy) at Microsoft.Kiota.Http.HttpClientLibrary.KiotaClientFactory.Create(HttpMessageHandler finalHandler, IRequestOption[] optionsForHandlers) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter..ctor(IAuthenticationProvider authenticationProvider, IParseNodeFactory parseNodeFactory, ISerializationWriterFactory serializationWriterFactory, HttpClient httpClient, ObservabilityOptions observabilityOptions) at Program.<>c.<$>b__0_0(IServiceProvider e) in /Users/brad/tmp/kiota-bug/KiotaBlazorBug/KiotaBlazorBug.Client/Program.cs:line 12 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass4_0.b__0(ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass9_0.g__Initialize|1(IServiceProvider serviceProvider, IComponent component) at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType, IComponentRenderMode callerSpecifiedRenderMode, Nullable`1 parentComponentId) at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] frames, Int32 frameIndex, Int32 parentComponentId) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException) at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry) at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
</details>


### Other information

_No response_
@brad-technologik brad-technologik added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Nov 21, 2024
@brad-technologik
Copy link
Author

I found that Using a custom HttpClient is a workaround. i.e:

var adapter = new HttpClientRequestAdapter(authProvider, httpClient: new HttpClient());

@baywet
Copy link
Member

baywet commented Nov 25, 2024

Hi @brad-technologik
Thank you for using kiota and for reaching out.

Does it make any difference if you use the kiota factory method instead to get the http client?

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Nov 25, 2024
@brad-technologik
Copy link
Author

Yes, using KiotaClientFactory.Create() results in the same crash, in fact I found that KiotaClientFactory.Create() is what causes the crash (even if you never assign that variable to anything).

I pushed my minimal repro. You can comment/uncomment this line to toggle the crash.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 27, 2024
@baywet
Copy link
Member

baywet commented Nov 28, 2024

Thank you for the additional information.

It's strange that blazor would be able to "translate" the call to new up an http client in the application code but not in a library.
My guess is that it's failing at the handler step.
Can you try calling that method and see whether that fails please?

public static HttpMessageHandler GetDefaultHttpMessageHandler(IWebProxy? proxy = null)

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Nov 28, 2024
@baywet baywet transferred this issue from microsoft/kiota Nov 28, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Nov 28, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Nov 28, 2024
@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Dec 6, 2024
@brad-technologik
Copy link
Author

@baywet

Can you re-open this bug? It's not resolved.

I provided sufficient reproduction steps and I don't have the time to perform debugging to narrow down the root cause but I think it should remain in a backlog somewhere.

@baywet baywet reopened this Dec 9, 2024
@github-project-automation github-project-automation bot moved this from Done ✔️ to In Progress 🚧 in Kiota Dec 9, 2024
@baywet baywet removed the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Dec 9, 2024
@baywet
Copy link
Member

baywet commented Dec 9, 2024

@brad-technologik can you at least take the time to run the last test I've suggested please?

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close status:needs-more-information An issue that requires additional information from issue author type:question An issue that's a question labels Dec 9, 2024
@baywet baywet moved this from In Progress 🚧 to Waits for author 🔁 in Kiota Dec 9, 2024

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Dec 17, 2024
@baywet baywet reopened this Dec 17, 2024
@github-project-automation github-project-automation bot moved this from Done ✔️ to In Progress 🚧 in Kiota Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-more-information An issue that requires additional information from issue author status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question
Projects
Status: In Progress 🚧
Development

No branches or pull requests

2 participants