.NET SDK (3.0.4 と 4.0.0-preview の両方) で存在しないインデックスのインデックスが存在するかどうかを確認しようとすると、ExistsAsync
(Exists
および とExistsWithHttpMessagesAsync
) は次の例外をスローします。
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Azure.Search.IndexesOperations.<GetWithHttpMessagesAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Search.ExistsHelper.<ExistsFromGetResponse>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Search.IndexesOperationsExtensions.<ExistsAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at InphizCore.MiddleLayer.Services.AzureSearch.Services.AzureSearchWriter`1.<AssertIndexExists>d__8.MoveNext() in C:\xxx\AzureSearchWriter.cs:line 109
postman から http rest を使用すると問題なく動作し、インデックスが存在しないというメッセージが返されます。
public async Task AssertIndexExists()
{
try
{
if (await searchServiceClient.Indexes.ExistsAsync(options.Value.IndexName) == false)
{
searchServiceClient.Indexes.Create(new Index(options.Value.IndexName, FieldBuilder.BuildForType<SearchableItemModel>(), corsOptions: new CorsOptions(new List<string> { "*" })));
}
}
catch (Exception e)
{
logger.LogError($"Azure Search Index '{options.Value.IndexName}' could not be created. ({e.Message})");
throw e;
}
}
これを意味のある方法でトラブルシューティングするにはどうすればよいですか?
アップデート:
これは、単体テストで実行されているときのクライアントの外観です。
これは、AspNetCore MVC からの外観です。
FirstMessageHandler
検索クライアントが、HttpClient
およびのインスタンスの作成に失敗したようHttpClientHandler
です。なぜ投げないのですか?