Reputation: 73
I'm trying to run a batch operation to merge some changes to an existing Azure Search Index, but I keep running into this error:
{Microsoft.Rest.Azure.CloudException: The request is invalid. Details: parameters : Object reference not set to an instance of an object.
Here's a snippet of my code:
public static void UploadData<T>(List<T> data, ISearchIndexClient indexClient) where T : class
{
int totalFailedToIndex = 0;
int totalPassedToIndex = 0;
for (int i = 0; i < data.Count; i = i + 500)
{
var stBatch = data.Skip(i).Take(500).ToList();
// Insert the data.
var serviceTreeBatch = IndexBatch.Merge(stBatch);
try
{
var index = indexClient.Documents.Index(serviceTreeBatch);
totalPassedToIndex += index.Results.Count();
}
catch (IndexBatchException e)
{
totalFailedToIndex += e.IndexingResults.Where(f => !f.Succeeded).Count();
}
catch(Exception e)
{
continue;
}
}
}
I've never seen this error before, and I can't seem to find anything online about it. Any help would definitely be appreciated!
Edit: Here's an example of the Type T that I'm passing in. The ProjectId is the key for these index items. It's also important to note that this version does not have all the index values (it's a merge so I'm only uploading the values that could possibly change along with the key). I'm wondering if the missing values is what's causing this to fail?
public class IndexItemModel
{
/// <summary>
/// Unique ProjectId
/// </summary>
public string ProjectId { get; set; }
public string RepositoryId { get; set; }
public IEnumerable<string> Repository_Users { get; set; }
public string Repository_UsersString { get; set; }
}
Upvotes: 3
Views: 1166
Reputation: 8634
This issue is caused by two separate problems:
[SerializePropertyNamesAsCamelCase]
attribute on the model class.If anybody else comes across this unhelpful error message, double-check that your field names match between the Index API and the index definition. Sorry for the inconvenience caused by this bug.
Upvotes: 3