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 #5807

Open
brad-technologik opened this issue Nov 21, 2024 · 1 comment
Open

Kiota C# Client crashes on Blazor WASM #5807

brad-technologik opened this issue Nov 21, 2024 · 1 comment
Labels
Csharp Pull requests that update .net code status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience

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 status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Nov 21, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Nov 21, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code 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());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience
Projects
Status: Needs Triage 🔍
Development

No branches or pull requests

1 participant