dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.23k stars 9.95k forks source link

Error while fetching api - .net5 #28487

Closed manasimahajann closed 3 years ago

manasimahajann commented 3 years ago

Blazor Webassembly and a separate api project - .net 5 Could you be able to advice--- followed below doc for logging in - works well https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory?view=aspnetcore-5.0

when try to fetch a record from api project

one network tab in browser -

blazor.boot.json | (canceled) | fetch | VM76 blazor.webassembly.js:1 | 0 B | 305 ms openid-configuration | (canceled) | xhr | VM78 AuthenticationService.js:1 | 0 B | 3 ms

on console - crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: An exception occurred executing JS interop: The JSON value could not be converted to System.DateTimeOffset. Path: $.token.expires | LineNumber: 0 | BytePositionInLine: 157.. See InnerException for more details. Microsoft.JSInterop.JSException: An exception occurred executing JS interop: The JSON value could not be converted to System.DateTimeOffset. Path: $.token.expires | LineNumber: 0 | BytePositionInLine: 157.. See InnerException for more details. ---> System.Text.Json.JsonException: The JSON value could not be converted to System.DateTimeOffset. Path: $.token.expires | LineNumber: 0 | BytePositionInLine: 157. ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a string. at System.Text.Json.Utf8JsonReader.TryGetDateTimeOffset(DateTimeOffset& value) at System.Text.Json.Utf8JsonReader.GetDateTimeOffset() at System.Text.Json.Serialization.Converters.DateTimeOffsetConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) at System.Text.Json.JsonPropertyInfo1[[System.DateTimeOffset, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, AccessToken& value) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, AccessToken& value) at System.Text.Json.JsonPropertyInfo1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, InternalAccessTokenResult& value) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, InternalAccessTokenResult& value) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[Object](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadValueCore[Object](JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state) at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options) at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 taskId, Boolean succeeded, Utf8JsonReader& jsonReader) --- End of inner exception stack trace --- at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__151[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext() at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService`3.d22[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteUserAccount, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.OidcProviderOptions, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext() at Downtown.Client.Services.Inherit.RequestToken.TokenAdded() in C:\dev\gxe_ws_downtown_b\Downtown.Client\Client\Services\Inherit\RequestToken.cs:line 31 at Downtown.Client.Services.Inherit.RequestToken.CheckAndAuthorize() in C:\dev\gxe_ws_downtown_b\Downtown.Client\Client\Services\Inherit\RequestToken.cs:line 51 at Downtown.Client.Services.CommissionAuditDataService.GetAllCommissionAudits() in C:\dev\gxe_ws_downtown_b\Downtown.Client\Client\Services\CommissionAuditDataService.cs:line 100 at Downtown.Client.Pages.MasterRecords.ComissionAudit.CommissionAuditOverview.OnInitializedAsync() in C:\dev\gxe_ws_downtown_b\Downtown.Client\Client\Pages\MasterRecords\ComissionAudit\CommissionAuditOverview.razor:line 82 at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle) d.printErr @ blazor.webassembly.js:1 d.preRun.push.window.Blazor._internal.dotNetCriticalError @ blazor.webassembly.js:1 w @ blazor.webassembly.js:1 _mono_wasm_invoke_js_blazor @ dotnet.5.0.0.js:1 do_icall @ 00aba1c6:0x194e46 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 w @ blazor.webassembly.js:1 _mono_wasm_invoke_js_blazor @ dotnet.5.0.0.js:1 do_icall @ 00aba1c6:0x194e46 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_invoke_checked @ 00aba1c6:0xf65a mono_runtime_try_invoke_array @ 00aba1c6:0x10e81f ves_icall_InternalInvoke @ 00aba1c6:0xed48f ves_icall_InternalInvoke_raw @ 00aba1c6:0xecf54 do_icall @ 00aba1c6:0x194dd3 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 beginInvokeDotNetFromJS @ blazor.webassembly.js:1 h @ blazor.webassembly.js:1 e.invokeMethodAsync @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 d @ blazor.webassembly.js:1 f @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 e.onGlobalEvent @ blazor.webassembly.js:1 Show 32 more frames blazor.webassembly.js:1 d.printErr @ blazor.webassembly.js:1 put_char @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 doWritev @ dotnet.5.0.0.js:1 _fd_write @ dotnet.5.0.0.js:1 stdio_write @ 00aba1c6:0xd9c25 fwritex @ 00aba1c6:0x7d006 fwrite @ 00aba1c6:0x6c60 fputs @ 00aba1c6:0x597ab default_stderr_handler @ 00aba1c6:0x197b69 monoeg_g_printerr @ 00aba1c6:0x1a34d mono_print_unhandled_exception_internal @ 00aba1c6:0x8de29 mono_unhandled_exception_checked @ 00aba1c6:0x10aa74 mono_unhandled_exception_internal @ 00aba1c6:0x62b59 mono_handle_exception_internal @ 00aba1c6:0x93aec mono_handle_exception @ 00aba1c6:0x94243 interp_throw @ 00aba1c6:0x5efc interp_exec_method @ 00aba1c6:0x49805 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 w @ blazor.webassembly.js:1 _mono_wasm_invoke_js_blazor @ dotnet.5.0.0.js:1 do_icall @ 00aba1c6:0x194e46 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_invoke_checked @ 00aba1c6:0xf65a mono_runtime_try_invoke_array @ 00aba1c6:0x10e81f ves_icall_InternalInvoke @ 00aba1c6:0xed48f ves_icall_InternalInvoke_raw @ 00aba1c6:0xecf54 do_icall @ 00aba1c6:0x194dd3 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 beginInvokeDotNetFromJS @ blazor.webassembly.js:1 h @ blazor.webassembly.js:1 e.invokeMethodAsync @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 d @ blazor.webassembly.js:1 f @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 e.onGlobalEvent @ blazor.webassembly.js:1 Show 44 more frames blazor.webassembly.js:1 Unhandled Exception: d.printErr @ blazor.webassembly.js:1 put_char @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 doWritev @ dotnet.5.0.0.js:1 _fd_write @ dotnet.5.0.0.js:1 __stdio_write @ 00aba1c6:0xd9c25 fwritex @ 00aba1c6:0x7d006 fwrite @ 00aba1c6:0x6c60 fputs @ 00aba1c6:0x597ab default_stderr_handler @ 00aba1c6:0x197b69 monoeg_g_printerr @ 00aba1c6:0x1a34d mono_print_unhandled_exception_internal @ 00aba1c6:0x8de29 mono_unhandled_exception_checked @ 00aba1c6:0x10aa74 mono_unhandled_exception_internal @ 00aba1c6:0x62b59 mono_handle_exception_internal @ 00aba1c6:0x93aec mono_handle_exception @ 00aba1c6:0x94243 interp_throw @ 00aba1c6:0x5efc interp_exec_method @ 00aba1c6:0x49805 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 w @ blazor.webassembly.js:1 _mono_wasm_invoke_js_blazor @ dotnet.5.0.0.js:1 do_icall @ 00aba1c6:0x194e46 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_invoke_checked @ 00aba1c6:0xf65a mono_runtime_try_invoke_array @ 00aba1c6:0x10e81f ves_icall_InternalInvoke @ 00aba1c6:0xed48f ves_icall_InternalInvoke_raw @ 00aba1c6:0xecf54 do_icall @ 00aba1c6:0x194dd3 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 beginInvokeDotNetFromJS @ blazor.webassembly.js:1 h @ blazor.webassembly.js:1 e.invokeMethodAsync @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 d @ blazor.webassembly.js:1 f @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 e.onGlobalEvent @ blazor.webassembly.js:1 Show 44 more frames blazor.webassembly.js:1 System.Text.Json.JsonException: Invalid JSON d.printErr @ blazor.webassembly.js:1 put_char @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 doWritev @ dotnet.5.0.0.js:1 _fd_write @ dotnet.5.0.0.js:1 stdio_write @ 00aba1c6:0xd9c25 __fwritex @ 00aba1c6:0x7d006 fwrite @ 00aba1c6:0x6c60 fputs @ 00aba1c6:0x597ab default_stderr_handler @ 00aba1c6:0x197b69 monoeg_g_printerr @ 00aba1c6:0x1a34d mono_print_unhandled_exception_internal @ 00aba1c6:0x8de29 mono_unhandled_exception_checked @ 00aba1c6:0x10aa74 mono_unhandled_exception_internal @ 00aba1c6:0x62b59 mono_handle_exception_internal @ 00aba1c6:0x93aec mono_handle_exception @ 00aba1c6:0x94243 interp_throw @ 00aba1c6:0x5efc interp_exec_method @ 00aba1c6:0x49805 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 w @ blazor.webassembly.js:1 _mono_wasm_invoke_js_blazor @ dotnet.5.0.0.js:1 do_icall @ 00aba1c6:0x194e46 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_invoke_checked @ 00aba1c6:0xf65a mono_runtime_try_invoke_array @ 00aba1c6:0x10e81f ves_icall_InternalInvoke @ 00aba1c6:0xed48f ves_icall_InternalInvoke_raw @ 00aba1c6:0xecf54 do_icall @ 00aba1c6:0x194dd3 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 beginInvokeDotNetFromJS @ blazor.webassembly.js:1 h @ blazor.webassembly.js:1 e.invokeMethodAsync @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 d @ blazor.webassembly.js:1 f @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 e.onGlobalEvent @ blazor.webassembly.js:1 Show 44 more frames blazor.webassembly.js:1 at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.EndInvokeJS(JSRuntime jsRuntime, String arguments) d.printErr @ blazor.webassembly.js:1 put_char @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 doWritev @ dotnet.5.0.0.js:1 _fd_write @ dotnet.5.0.0.js:1 stdio_write @ 00aba1c6:0xd9c25 fwritex @ 00aba1c6:0x7d006 fwrite @ 00aba1c6:0x6c60 fputs @ 00aba1c6:0x597ab default_stderr_handler @ 00aba1c6:0x197b69 monoeg_g_printerr @ 00aba1c6:0x1a34d mono_print_unhandled_exception_internal @ 00aba1c6:0x8de29 mono_unhandled_exception_checked @ 00aba1c6:0x10aa74 mono_unhandled_exception_internal @ 00aba1c6:0x62b59 mono_handle_exception_internal @ 00aba1c6:0x93aec mono_handle_exception @ 00aba1c6:0x94243 interp_throw @ 00aba1c6:0x5efc interp_exec_method @ 00aba1c6:0x49805 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 w @ blazor.webassembly.js:1 _mono_wasm_invoke_js_blazor @ dotnet.5.0.0.js:1 do_icall @ 00aba1c6:0x194e46 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_invoke_checked @ 00aba1c6:0xf65a mono_runtime_try_invoke_array @ 00aba1c6:0x10e81f ves_icall_InternalInvoke @ 00aba1c6:0xed48f ves_icall_InternalInvoke_raw @ 00aba1c6:0xecf54 do_icall @ 00aba1c6:0x194dd3 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 beginInvokeDotNetFromJS @ blazor.webassembly.js:1 h @ blazor.webassembly.js:1 e.invokeMethodAsync @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 d @ blazor.webassembly.js:1 f @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 e.onGlobalEvent @ blazor.webassembly.js:1 Show 44 more frames blazor.webassembly.js:1 at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.EndInvokeJS(String argsJson) d.printErr @ blazor.webassembly.js:1 put_char @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 write @ dotnet.5.0.0.js:1 doWritev @ dotnet.5.0.0.js:1 _fd_write @ dotnet.5.0.0.js:1 __stdio_write @ 00aba1c6:0xd9c25 fwritex @ 00aba1c6:0x7d006 fwrite @ 00aba1c6:0x6c60 fputs @ 00aba1c6:0x597ab default_stderr_handler @ 00aba1c6:0x197b69 monoeg_g_printerr @ 00aba1c6:0x1a34d mono_print_unhandled_exception_internal @ 00aba1c6:0x8de29 mono_unhandled_exception_checked @ 00aba1c6:0x10aa74 mono_unhandled_exception_internal @ 00aba1c6:0x62b59 mono_handle_exception_internal @ 00aba1c6:0x93aec mono_handle_exception @ 00aba1c6:0x94243 interp_throw @ 00aba1c6:0x5efc interp_exec_method @ 00aba1c6:0x49805 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 w @ blazor.webassembly.js:1 _mono_wasm_invoke_js_blazor @ dotnet.5.0.0.js:1 do_icall @ 00aba1c6:0x194e46 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_invoke_checked @ 00aba1c6:0xf65a mono_runtime_try_invoke_array @ 00aba1c6:0x10e81f ves_icall_InternalInvoke @ 00aba1c6:0xed48f ves_icall_InternalInvoke_raw @ 00aba1c6:0xecf54 do_icall @ 00aba1c6:0x194dd3 do_icall_wrapper @ 00aba1c6:0x79df6 interp_exec_method @ 00aba1c6:0x44ad0 interp_runtime_invoke @ 00aba1c6:0x12efed mono_jit_runtime_invoke @ 00aba1c6:0x118e4d do_runtime_invoke @ 00aba1c6:0x79d3f mono_runtime_try_invoke @ 00aba1c6:0x1297f mono_runtime_invoke @ 00aba1c6:0x10ec19 mono_wasm_invoke_method @ 00aba1c6:0x108e40 Module._mono_wasm_invoke_method @ dotnet.5.0.0.js:1 call_method @ dotnet.5.0.0.js:1 (anonymous) @ dotnet.5.0.0.js:1 beginInvokeDotNetFromJS @ blazor.webassembly.js:1 h @ blazor.webassembly.js:1 e.invokeMethodAsync @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 r @ blazor.webassembly.js:1 d @ blazor.webassembly.js:1 f @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 e.onGlobalEvent @ blazor.webassembly.js:1 Show 44 more frames dotnet.5.0.0.js:1 Uncaught (in promise) Error: System.Text.Json.JsonException: Invalid JSON at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.EndInvokeJS(:44307/JSRuntime jsRuntime, String arguments) at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.EndInvokeJS(:44307/String argsJson)

guardrex commented 3 years ago

:eyes: on this one for potential doc updates later.

pranavkm commented 3 years ago

The JSON value could not be converted to System.DateTimeOffset.

Are you able to inspect the browser network tab and say what the returned value is? System.Text.Json is strict about how date times are parsed, so it's possible that the date being read is not a valid value.

manasimahajann commented 3 years ago

@guardrex Yes would be helpful.. @pranavkm

error

This is what I am seeing in my network tab!!!

guardrex commented 3 years ago

System.Text.Json is strict about how date times are parsed

I don't have enough context (and knowledge) to cover it myself. I recommend that @pranavkm provide the appropriate section (section heading and content) for the topic (if we cover something for this), and I'll run it through the Rex-o-matic Doc Generator:tm: for the topic.

@pranavkm ... I'll take anything you paste in here, re-open the original doc issue, and work it in from there.

pranavkm commented 3 years ago

@manasimahajann could you inspect the response that triggers the JSON deserialization? It's likely the ProcessAuth request. The idea is to inspect the JSON payload being returned to figure out why it results in an error

manasimahajann commented 3 years ago

@pranavkm Thank you for getting back. In our code we are requesting a token using HttpClient httpClient, NavigationManager Navigation and IAccessTokenProvider AuthenticationService... The code comes out at var tokenResult = await _AuthenticationService.RequestAccessToken(); I am not able to reach to the response of json deserialization as authentication is not processing. on api side I have -

        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAd"));

        services.Configure<JwtBearerOptions>(
           JwtBearerDefaults.AuthenticationScheme, options =>
           { 
               options.TokenValidationParameters.NameClaimType = "name";
           });

On client side -

        builder.Services.AddOidcAuthentication(options =>
        { 
            builder.Configuration.Bind("AzureAd", options.ProviderOptions);
            options.ProviderOptions.DefaultScopes.Add("api://00000000-0000-0000-0000-000000000000"); 
        });

Let me know if you would require more info..

pranavkm commented 3 years ago

You should be able to see the response that the browser receives in the network tab, no?

manasimahajann commented 3 years ago
error2 error3

Is this what you are suggesting?

pranavkm commented 3 years ago

Yes, specifically the response tab which would include the body of the response.

manasimahajann commented 3 years ago
error4

yes right. it does not really give me any info for the .json file

jmagaram commented 3 years ago

I might have something of value to add to this issue. I've been trying to get Blazor WASM to work with authentication using Microsoft Accounts and Google Accounts. I've tried to follow step-by-step instructions on the Microsoft docs web site for creating the basic projects. The UI does bring up the Microsoft and Google authentication UI and does not display any errors. I've seen the user accounts listed in the Azure B2C console. So it seems like authentication is working. But when I go to the FetchData.razor page, I get the browser error about "cannot convert DateTimeOffset". Super frustrating. I opened the dev tools Network tab and it looks like the tokens that gets downloaded are ok - no syntax errors or anything reported by https://jwt.ms/. Here is a token for example:

eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrNHh5b2pORnVtMWtsMll0djhkbE5QNC1jNTdkTzZRR1RWQndhTmsifQ.eyJleHAiOjE2MTAwNTk0MjksIm5iZiI6MTYxMDA1NTgyOSwidmVyIjoiMS4wIiwiaXNzIjoiaHR0cHM6Ly9ncm9jZXJpZXNiMmMuYjJjbG9naW4uY29tLzU1MDE1ZWE3LWExOTEtNGFlMy05NmU0LTgzNmRjYzBhZDI5Ny92Mi4wLyIsInN1YiI6IjVlZTk2M2ZiLTI0ZDYtNGQ3Mi1hMWI2LTg4OWM2ZTJjNzQzOCIsImF1ZCI6IjcwYmRlMzc1LWZjZTMtNGI4Mi05ODRhLWIyNDdkODIzYTAzZiIsIm5vbmNlIjoiYjI2NDFmNTQtOGRjNC00MmNhLTk3ZWEtN2YxMmZmNGFmODcxIiwiaWF0IjoxNjEwMDU1ODI5LCJhdXRoX3RpbWUiOjE2MTAwNTU4MjIsImlkcCI6Imdvb2dsZS5jb20iLCJ0ZnAiOiJCMkNfMV9zaWdudXBzaWduaW4ifQ.q3BG4H3Nm4drB1ssQTs3TrLYo72PhTUGlZvU9lpS-yGqa51SopyrU-KS5MwKq7xWXkEC87d_YozDQvD1jxQlkPhBt_sD8stmesqI7IwKLp0PJOKKd2cxaZWcm-LHMCL29N8Ct1dkYEC3bcnEP2IcyckaHGjA7C9PHpvhsgTUxyKanLtVnAAsWrCVxm_xcE19MDTdSsTeEwi9WtbQdHBHGcQQRbW7Wmo6SWYG4V_bU55Ug_PW4pLPr20tTS8Ct7_uwy9DWrzCMzpD-EiwT5IjXwlGX3IXVjHIlX50IVIydBoPQtadvT7saKo1G5Jmutgq41o-dmz6-yBMKV2_nXA25Q

Don't have a clue how to fix this.

manasimahajann commented 3 years ago

Totally understand your frustration. we have for now switched to Azure AD

justmccullough commented 3 years ago

In case anyone heads down this rabbit hole. I was getting the exact same error using Blazor WASM, MSAL and AAD B2C with .NET 5. It was an issue of some missing API configuration in the B2C tenant. I found the true error in the GET token endpoint in the Network Tab in Edge. This showed me the app didn't have access to the API I was requesting. I dropped the API permission from the app and re-added it. Worked just fine after that.

davhdavh commented 3 years ago

The problem occurs because the function getAccessTokenin AuthenticationService.js assumes that a successful token from the server is always an access_token. Therefore the fix is to not make the default out-of-the-box token flow requested an id-token, but rather a code flow. Secondary fix is to check the return value of signinSilentin and getAccessToken to ensure that it actually returned an access_code.

gallwood commented 3 years ago

@davhdavh , sorry, but I too have this same issue when calling my Azure API, using B2C authentication from a Blazor (WASM) client. Do you know how I can request code flow rather than id_token when using the class AddMsalAuthentication?

ghost commented 3 years ago

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!