Open nssidhu opened 2 years ago
Adding some more information on DI. I have tried Singleton & Scoped as well
builder.Services.AddTransient<RefitAuthHeaderHandler>();
var setting = new RefitSettings
{
ContentSerializer = new NewtonsoftJsonContentSerializer(
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
})
};
builder.Services.AddRefitClient<IXXXXHttpAPI>(setting)
.ConfigureHttpClient(c =>
{
c.BaseAddress = new System.Uri("https://XXXXXappdev.azurewebsites.net/api");
})
.AddHttpMessageHandler<RefitAuthHeaderHandler>();
Describe the bug
I am getting the following error, only when adding AddHttpMessageHandler.
{System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.AspNetCore.Components.WebView.Services.WebViewJSRuntime.BeginInvokeJS(Int64 taskId, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId) at Microsoft.JSInterop.JSRuntime.InvokeAsync[String](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, PublicKeyToken=7cec85d7bea7798e]].MoveNext()Object[] args) at Microsoft.JSInterop.JSRuntime.d__16`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
at SharedClassLibrary.RefitAuthHeaderHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in C:\Users\admin\Source\Repos\XXXX\XXXXXHybridApp\SharedClassLibrary\RefitAuthHeaderHandler.cs:line 26}
it this line that throws error
var token = await _jsRuntime.InvokeAsync<string>("localStorage.getItem", JsAuthTokenName);
when i debug i do see it like this
Here my Auth Handler class Note: i had to comment InnerHandler line
Now i am using JSRuntime in other places and i noticed that in those other place there is a value for the _ipcSender
Expected behavior JSRuntime should not throw Error
Screenshots
Environment
I am using Visual Studio 2022 Version 17.1.0 Preview 6.0 using .NET 6.0
The error is showing up when running for android.