Does Azure Document Intelligence C# SDK support add-on query field?

Ubana, Siddharth 20 Reputation points
2025-04-22T14:42:10.89+00:00

Hi,

I am trying to use the query fields feature using the Azure .NET C# SDK but I am getting below error on calling the method. Could you please help me.

Error details -

ErrorCode: InvalidArgument Content: {"error":{"code":"InvalidArgument","message":"Invalid argument.","innererror":{"code":"ParameterMissing","message":"The parameter urlSource or base64Source is required."}}}

Below is the code I used. Content is a byte array passed in the method parameters which is having this code.

BinaryData data = BinaryData.FromBytes(Content);

var queryFields = new List<string>() { "FullName", "CompanyName", "JobTitle" };

Operation<BinaryData> operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, modelId, data, "1-2", queryFields: queryFields, features: new List<DocumentAnalysisFeature>() { DocumentAnalysisFeature.QueryFields });

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,026 questions
{count} votes

Accepted answer
  1. Sina Salam 19,616 Reputation points
    2025-04-28T12:24:35.8866667+00:00

    Hello Ubana, Siddharth,

    Issue:

    Customer trying to use the query fields feature using the Azure .NET C# SDK and asked if Azure Document Intelligence C# SDK support add-on query field.

    Error Message:

    ErrorCode: InvalidArgument Content: {"error":{"code":"InvalidArgument","message":"Invalid argument.","innererror":{"code":"ParameterMissing","message":"The parameter urlSource or base64Source is required."}}}

    Solution:

    Among all the suggested answers, customer use AnalyzeDocumentOptions to directly add the query fields and call AnalyzeDocumentAsync with the AnalyzeDocumentOptions.

    The steps are as follow:

    1. Create BinaryData from the document content.
    2. Initialize AnalyzeDocumentOptions with the model ID, BinaryData, and other parameters.
    3. Add QueryFields directly to AnalyzeDocumentOptions.
    4. Call AnalyzeDocumentAsync with the AnalyzeDocumentOptions.

    The code example:

    BinaryData data = BinaryData.FromBytes(Content);
    var analyzeOptions = new AnalyzeDocumentOptions(modelId, data) 
    { 
      Pages = "1-2", 
      Features = { DocumentAnalysisFeature.QueryFields }, 
      QueryFields = { "FullName", "CompanyName", "JobTitle" } 
    };
    Operation<AnalyzeResult> operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, analyzeOptions);
    AnalyzeResult result = operation.Value;
    

    If this is helpful, don't forget to close up the thread here by upvoting and accept it as an answer.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Sina Salam 19,616 Reputation points
    2025-04-27T16:22:10.92+00:00

    Hello Ubana, Siddharth,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Regarding your question: Does Azure Document Intelligence C# SDK support add-on query field? and explanations.

    To avoid any confusion due to outdated or incompatible GitHub samples uses in preview SDK v4.0.0-beta.1 or beta SDKs, which is not the 1.0.0 stable release.

    This is what needs to happen since you're using Azure.AI.DocumentIntelligence v1.0.0 you must manually build a proper payload structure including the queryFields. The SDK expects a JSON structure similar to:

    {
      "queryFields": [
        {"key": "FullName"},
        {"key": "CompanyName"},
        {"key": "JobTitle"}
      ]
    }
    

    So, you need to create this JSON and wrap it as BinaryData.

    This is updated and correct C# code:

    using Azure;
    using Azure.AI.DocumentIntelligence;
    using System.Text.Json;
    // Create the queryFields JSON payload
    var queriesPayload = new
    {
        queryFields = new[]
        {
            new { key = "FullName" },
            new { key = "CompanyName" },
            new { key = "JobTitle" }
        }
    };
    // Serialize the payload to JSON
    string jsonPayload = JsonSerializer.Serialize(queriesPayload);
    // Convert it to BinaryData
    BinaryData requestData = BinaryData.FromString(jsonPayload);
    // Now call AnalyzeDocumentAsync properly
    Operation<AnalyzeResult> operation = await client.AnalyzeDocumentAsync(
        WaitUntil.Completed,
        modelId,
        requestData,
        "1-2",
        features: new List<DocumentAnalysisFeature> { DocumentAnalysisFeature.QueryFields }
    );
    // Get the result
    AnalyzeResult result = operation.Value;
    // You can now inspect 'result' for your extracted query fields
    

    Notes that:

    The content (your document) must already be embedded into the payload, or you need to use a URL document source. The "1-2" parameter is for API version.

    • If this is causing issues, double-check that your SDK supports the intended service API version.
    • If you want to send document content, you must use a base64 encoded document inside the payload.
    • Otherwise, or local files, you must use Upload mode.

    Check out the Azure Document Intelligence SDK for .NET v1.0.0 - AnalyzeDocumentAsync API - https://learn.microsoft.com/en-us/dotnet/api/azure.ai.documentintelligence.documentanalysisclient.analyzedocumentasync?view=azure-dotnet

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.