Visual Studio 2022でデバック実行したら”CreateHostBuilder(args).Build().Run();”でエラーが出た。

Visual Studio 2022でデバック実行したら”CreateHostBuilder(args).Build().Run();”でエラーになった。もともと、動作していた環境なのだが、久しぶりに起動させたところ、デバック実行で起動できなくなっていた。環境は、Visual Studio 2022、.NET6。

■エラーになった個所:Program.CS

CreateHostBuilder(args).Build().Run();

■表示されたエラーやログ

'xxxxxxxxx.exe' (CoreCLR: clrhost): 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.13\System.Security.Cryptography.Csp.dll' が読み込まれました。シンボルの読み込みをスキップしました。モジュールは最適化されていて、デバッグ オプションの [マイ コードのみ] 設定が有効になっています。
例外がスローされました: 'System.InvalidOperationException' (System.Private.CoreLib.dll の中)
型 'System.InvalidOperationException' のハンドルされていない例外が System.Private.CoreLib.dll で発生しました
Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.

いろいろと試した結果・・・

次のコマンド(2つ)を、Visual Studio 2022 とは別にPowershellを開いて、実行した。そのあと、Visual Studioでデバック実行して正常にウェブアプリが起動することが確認できた。

dotnet dev-certs https --clean
dotnet dev-certs https --trust

“dotnet dev-certs https –trust”のみの実行だと、変らなくて、Cleanのオプションで使っていない証明書をきれいにすることで解消した。ここがわかるまで、結構時間を使ってしまった。

スポンサーリンク

シェアする

  • このエントリーをはてなブックマークに追加

フォローする