/// <summary>
        /// Read the start of the top-level data wrapper in JSON responses.
        /// </summary>
        /// <param name="payloadKind">The kind of payload we are reading; this guides the parsing of the context URI.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker.</param>
        /// <param name="isReadingNestedPayload">true if we are deserializing a nested payload, e.g. an entry, a feed or a collection within a parameters payload.</param>
        /// <param name="allowEmptyPayload">true if we allow a comletely empty payload; otherwise false.</param>
        /// <returns>The parsed context URI.</returns>
        /// <remarks>
        /// Pre-Condition:  JsonNodeType.None:      assumes that the JSON reader has not been used yet when not reading a nested payload.
        /// Post-Condition: The reader is positioned on the first property of the payload after having read (or skipped) the context URI property.
        ///                 Or the reader is positioned on an end-object node if there are no properties (other than the context URI which is required in responses and optional in requests).
        /// </remarks>
        internal Task ReadPayloadStartAsync(
            ODataPayloadKind payloadKind,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            bool isReadingNestedPayload,
            bool allowEmptyPayload)
        {
            this.JsonReader.AssertNotBuffering();
            Debug.Assert(isReadingNestedPayload || this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: JSON reader must not have been used yet when not reading a nested payload.");

            return(TaskUtils.GetTaskForSynchronousOperation(() =>
            {
                string contextUriAnnotationValue = this.ReadPayloadStartImplementation(
                    payloadKind,
                    duplicatePropertyNamesChecker,
                    isReadingNestedPayload,
                    allowEmptyPayload);

                // The context URI is only recognized in non-error response top-level payloads.
                // If the payload is nested (for example when we read URL literals) we don't recognize the context URI.
                // Top-level error payloads don't need and use the context URI.
                if (!isReadingNestedPayload && payloadKind != ODataPayloadKind.Error && contextUriAnnotationValue != null)
                {
                    this.contextUriParseResult = ODataJsonLightContextUriParser.Parse(
                        this.Model,
                        contextUriAnnotationValue,
                        payloadKind,
                        this.MessageReaderSettings.ReaderBehavior,
                        this.JsonLightInputContext.ReadingResponse);
                }

#if DEBUG
                this.contextUriParseResultReady = true;
#endif
            }));
        }
        /// <summary>
        /// Read the start of the top-level data wrapper in JSON responses.
        /// </summary>
        /// <param name="payloadKind">The kind of payload we are reading; this guides the parsing of the context URI.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker.</param>
        /// <param name="isReadingNestedPayload">true if we are deserializing a nested payload, e.g. an entry, a feed or a collection within a parameters payload.</param>
        /// <param name="allowEmptyPayload">true if we allow a comletely empty payload; otherwise false.</param>
        /// <remarks>
        /// Pre-Condition:  JsonNodeType.None:      assumes that the JSON reader has not been used yet when not reading a nested payload.
        /// Post-Condition: The reader is positioned on the first property of the payload after having read (or skipped) the context URI property.
        ///                 Or the reader is positioned on an end-object node if there are no properties (other than the context URI which is required in responses and optional in requests).
        /// </remarks>
        internal void ReadPayloadStart(
            ODataPayloadKind payloadKind,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            bool isReadingNestedPayload,
            bool allowEmptyPayload)
        {
            this.JsonReader.AssertNotBuffering();
            Debug.Assert(isReadingNestedPayload || this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: JSON reader must not have been used yet when not reading a nested payload.");

            string contextUriAnnotationValue = this.ReadPayloadStartImplementation(
                payloadKind,
                duplicatePropertyNamesChecker,
                isReadingNestedPayload,
                allowEmptyPayload);

            ODataJsonLightContextUriParseResult parseResult = null;

            // The context URI is only recognized in non-error response top-level payloads.
            // If the payload is nested (for example when we read URL literals) we don't recognize the context URI.
            // Top-level error payloads don't need and use the context URI.
            if (!isReadingNestedPayload && payloadKind != ODataPayloadKind.Error)
            {
                parseResult = this.jsonLightInputContext.PayloadKindDetectionState == null
                    ? null
                    : this.jsonLightInputContext.PayloadKindDetectionState.ContextUriParseResult;
                if (parseResult == null && contextUriAnnotationValue != null)
                {
                    parseResult = ODataJsonLightContextUriParser.Parse(
                        this.Model,
                        contextUriAnnotationValue,
                        payloadKind,
                        this.Version,
                        this.MessageReaderSettings.ReaderBehavior,
                        this.JsonLightInputContext.ReadingResponse);
                }
            }

            this.contextUriParseResult = parseResult;
#if DEBUG
            this.contextUriParseResultReady = true;
#endif
        }