3

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; }
}
Michelle
  • 63
  • 1
  • 4
  • 1
    I don't see anything wrong with your code. From the error message, it looks like a bug, possibly in the service itself. To help us troubleshoot this, can you please edit your question to include at least one of the types that maps to the type parameter T? That would help us to reproduce the problem. Thanks! – Bruce Johnston Jul 04 '19 at 05:38
  • Okay I've added an edit to include T. I wonder if I'm misusing the merge call in any way? Do I need to have all index values in order to do the merge? – Michelle Jul 04 '19 at 16:43
  • Scratch that, I added in all the index values and it still gives me that exception. I use this code in another project, the only difference is that this runs in a feed observer while the other is a webjob – Michelle Jul 04 '19 at 16:59
  • Does the error happen on the very first batch? – Bruce Johnston Jul 04 '19 at 20:05
  • Also, which version of the .NET SDK are you using? – Bruce Johnston Jul 04 '19 at 23:00
  • Yep, the error occurs on the first batch. I've tried using version 9.0.1 and 5.0.3 of the Azure search sdk and the issue repros on both. – Michelle Jul 05 '19 at 18:06
  • So far I've been unable to find enough information in the logs to troubleshoot this on my end. Would you mind contacting me directly so I can get some more specific information about your Search service? My contact e-mail is bruce dot johnston at microsoft. – Bruce Johnston Jul 05 '19 at 22:05

1 Answers1

3

This issue is caused by two separate problems:

  1. The field names in the Index API request don't match the index definition (confirmed via troubleshooting). The root cause was a missing [SerializePropertyNamesAsCamelCase] attribute on the model class.
  2. At the time of this writing (July 2019), there is a bug in the Azure Search Index REST API that results in the unhelpful error message "Object reference not set to an instance of an object" being returned instead of a more helpful error message. This is a regression. The expected behavior is an error message that names the unrecognized field and specifically says that the field name isn't recognized.

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.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
  • Hi Bruce, this issue still persists as of today, 16th April 2021. I've had a mismatch between the index definition and the data I was sending over and I got the same issue, with the same unhelpful message: "Object reference not set to an instance of an object" – Albert Herd Apr 16 '21 at 14:41
  • @BruceJohnston I'm also still seeing this issue, and, given that I think that I have got my fields and index fields matched up, is a major problem. Any word on this getting fixed? Or any suggestion for how else to debug it? – Paul Manzotti Apr 23 '21 at 10:00
  • @PaulManzotti Sorry for the late response; I'm currently on leave. If this is still blocking you, I recommend you open a support case and have the support engineer escalate to the product team. – Bruce Johnston Apr 30 '21 at 17:36