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

IJSRuntime : {System.NullReferenceException: Object reference not set to an instance of an object. in DelegatingHandler #443

Open
nssidhu opened this issue Feb 15, 2022 · 2 comments

Comments

@nssidhu
Copy link

nssidhu commented Feb 15, 2022

@Eilon

I have filed the bug on with Refit, but was wondering if something is already known about this.
I am trying to use IJSRuntime in Refit as for Adding Auth token using Delegating handler.

reactiveui/refit#1316

@Eilon
Copy link
Member

Eilon commented Feb 15, 2022

Hi @nssidhu , I think I've seen things like this happen when the wrong Dependency Injection (DI) scope is used. I think the IJSRuntime service can be consumed only from transitive or scoped services, but not from singleton service. Maybe that's the issue here?

@nssidhu
Copy link
Author

nssidhu commented Feb 15, 2022

I tried all singleton, transient & scoped, same error

builder.Services.AddScoped<RefitAuthHeaderHandler>();

            var setting = new RefitSettings
            {
                ContentSerializer = new NewtonsoftJsonContentSerializer(
                            new JsonSerializerSettings
                            {
                                ContractResolver = new CamelCasePropertyNamesContractResolver()
                            })
            };

            builder.Services.AddRefitClient<IXXXXXXXHttpAPI>(setting)
            .ConfigureHttpClient(c =>
                {
                    c.BaseAddress = new System.Uri("https://XXXXXppdev.azurewebsites.net/api");
                })
            .AddHttpMessageHandler<RefitAuthHeaderHandler>();

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

No branches or pull requests

2 participants