Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

The emitter failed when pagination properties (@nextLink, @pageItems) were defined in base models rather than directly on the response model. Property lookups used Properties.First() which only searched direct properties, causing InvalidOperationException for inherited properties.

Changes

  • Added recursive property lookup: New FindPropertyInModelHierarchy() method traverses the model inheritance chain to locate properties defined in base classes
  • Updated CollectionResultDefinition.GetNextPagePropertyType(): Replaced direct property access with hierarchy-aware lookup
  • Updated ModelProviderSnippets.BuildPropertyAccessExpression(): Applied same pattern for consistency across property access paths
  • Added test coverage: 4 test cases covering sync/async and generic/non-generic scenarios with inherited pagination properties

Example

Now supports this pattern:

model ResponseList {
  @nextLink
  nextLink?: string;
}

model FooResponseList extends ResponseList {
  @pageItems
  value?: FooResource[];
}

Previously, the emitter would throw when trying to locate nextLink on FooResponseList since it only checked direct properties.

Original prompt

This section details on the original issue you should resolve

<issue_title>[http-client-csharp] failed to find nested nextLink property for a list operation</issue_title>
<issue_description>If the response model is inherited from another model that only defines nextLink, like this:

model ResponseList {
  /**
   * The uri to fetch the next page of resources. Call ListNext() fetches next page of resources.
   */
  @nextLink
  nextLink?: string;
}

model FooResponseList extends ResponseList {
  /**
   * List of resources.
   */
  @pageItems
  value?: FooResource[];
}

Then the emitter throws an exception because it doesn’t check for nested nextLink values. This results in an error like the following:

      Sequence contains no matching element
         at System.Linq.ThrowHelper.ThrowNoMatchException()
         at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.CollectionResultDefinition.GetNextPagePropertyType()
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.CollectionResultDefinition..ctor(ClientProvider client, InputPagingServiceMethod serviceMethod, CSharpType itemModelType, Boolean isAsync)
         at Azure.Generator.Providers.AzureCollectionResultDefinition..ctor(ClientProvider client, InputPagingServiceMethod serviceMethod, CSharpType itemModelType, Boolean isAsync)
         at Azure.Generator.Providers.AzureClientResponseProvider.CreateClientCollectionResultDefinition(ClientProvider client, InputPagingServiceMethod serviceMethod, CSharpType type, Boolean isAsync)
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.ScmMethodProviderCollection.BuildProtocolMethod(MethodProvider createRequestMethod, Boolean isAsync, Boolean shouldMakeParametersRequired)
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.ScmMethodProviderCollection.BuildMethods()
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.ScmMethodProviderCollection.get_MethodProviders()
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.ScmMethodProviderCollection.GetEnumerator()
         at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.ClientProvider.BuildMethods()
         at Microsoft.TypeSpec.Generator.Providers.TypeProvider.get_Methods()
         at Microsoft.TypeSpec.Generator.ClientModel.Providers.ClientProvider.GetMethodCollectionByOperation(InputOperation operation)
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix error finding nested nextLink property in response model Fix property lookup to support inheritance in pagination response models Jan 20, 2026
Copilot AI requested a review from ArthurMa1978 January 20, 2026 14:53
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jan 20, 2026
@JoshLove-msft JoshLove-msft added this pull request to the merge queue Jan 20, 2026
Merged via the queue into main with commit cf050c6 Jan 20, 2026
22 of 24 checks passed
@JoshLove-msft JoshLove-msft deleted the copilot/fix-nested-nextlink-error branch January 20, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-csharp] failed to find nested nextLink property for a list operation

4 participants