事象
Blazor(WASM) + ASP.Netで作成したアプリをAzure AppSerivceにデプロイし認証をテストしたところ
'Cannot read property 'toLowerCase' of undefined' を吐き出しエラーが発生
ローカルPCでデバッガーで動作したところ問題なく動作
環境
.Net6 + VS2022 + AzureAD B2C
dotnet new blazorwasm -au IndividualB2C
にてテンプレートを作成しました
なお、.Net5でも同様のアプリを作成したことがあり、その時は動作しているので.Net6以降の問題だと思われます
現象
AppServiceにデプロイ後アプリを開きログインボタンを押すと
Authentication.razorの
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" /> <----このコントロール
@code{
[Parameter] public string? Action { get; set; }
}
RemoteAuthenticatorViewが'Cannot read property 'toLowerCase' of undefined'
というエラーを吐いているところまで突き止めました。
対応策
ネットを見てみると同様のエラーで困っている人を発見
だが、Net 6 Preview 4とやや古い環境なので参考になるか?と思いつつ試してみたら治りました。
- Clientプロジェクト(*.csproj)に
<ItemGroup>
<TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
</ItemGroup>
を追加
2. Clientのbin、objフォルダを一度削除後、再ビルドしデプロイ
英語が得意ではないためなぜ?という部分が不明なのですが、対処療法として記述しました。
いずれ根本的な解決がなされることを期待しています