Skip to content

Dispatch inherited operation methods in generated data portal code - #5048

Merged
rockfordlhotka merged 4 commits into
mainfrom
issue-5046/generated-data-portal-mapping-throws-for-inherited
Nov 20, 2026
Merged

rockfordlhotka merged 4 commits into
mainfrom
issue-5046/generated-data-portal-mapping-throws-for-inherited

Conversation

@rockfordlhotka

@rockfordlhotka rockfordlhotka commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The data portal operations generator now includes the operation methods a concrete class inherits in its generated IDataPortalOperationMapping / IDataPortalOperationNamedMapping code. Before, an operation on a base class (a project base like AppBase<T>, or CSLA's own BusinessBase.Child_Create and the lists' Child_UpdateAsync) made the generated code throw DataPortalOperationNotSupportedException. The data portal caught it and fell back to reflection, but the debugger broke on it.
  • Inherited methods are chosen the way ServiceProviderMethodCaller chooses them:
    • Private base methods are not included.
    • A method closer to the class wins. Within an operation name, the score is the number of injected parameters minus the inheritance depth, and a tie is left to reflection, which reports it as ambiguous.
    • An override without the attribute is called virtually, at the override's level.
    • When the class declares a member with the same name, the inherited method is called through base..
  • Criteria dispatch uses reflection's scoring: exact type 3, assignable 2, object 1, minus inheritance depth, plus injected parameters. For every other method of the same kind and criteria count, it compares this method's lowest possible score with the other's highest. When the other could tie or win, the method is guarded against criteria that match the other, so those calls are left to reflection. This includes methods the generated code cannot call: hidden, inaccessible, or with types the interface cannot name. Guards are skipped between types that no value can match both.
  • A subclass of an operation attribute counts as that attribute for inherited methods, as it does at runtime. Generic operation methods, and declared methods marked with a subclass of an operation attribute, leave their kind entirely to reflection.
  • A lone params object[] operation method is dispatched with the whole criteria array, as reflection does, when it is the only method of its kind. This covers child lists that declare their own operations.
  • The generated code leaves a method to reflection when calling it could bind to the wrong overload, because an intermediate class declares a same-name member. It also does when the method takes or returns a private or protected nested type, which the internal interface cannot name. For declared methods that used to be a CS0051 compile error in the generated code.
  • CSLADP002/CSLADP009 now report collisions between a declared method and an inherited one, at the declared method. Extension methods still cover only declared methods; overrides of inherited operations get none.
  • Inherited methods are added once per type, in their own pipeline step (InheritedOperationMethods).
  • Existing snapshots change because every concrete class now dispatches the inherited BusinessBase.Child_Create. In ChildOperations the class declares its own [CreateChild], which wins. The ParamsArrayAndKeywordNames snapshot now dispatches the params object[] method.
  • GeneratedInterfaceMemberNames_MatchRuntimeOperationNames now finds each interface member's method at the nearest declaring type, since the interface can name inherited methods.
  • Added a docs section in data-portal-operations-generator.md and a release note.

Test plan

  • Generator tests: 193 pass on net10.0 and net11.0. New snapshots cover:
    • injected-parameter scoring across levels
    • inherited and declared methods marked with derived operation attributes
    • a generic base class (the issue's scenario)
    • a base. call
    • hiding by an intermediate class
    • an override without the attribute
    • a same-shape overload across levels
    • cross-level scoring, with its CSLADP002/CSLADP009 diagnostics
    • inherited protected nested criteria and declared private nested criteria
    • a child list's inherited params object[] update
    • inherited methods and overrides getting no extensions
  • New runtime test InheritedOperationDispatchTests (csla.netcore.test) counts first-chance DataPortalOperationNotSupportedExceptions during create, fetch, and insert/update saves of a root with a child list that declares its own operation. It passes with the fix and fails on main.
  • Full CI suite (csla.test.slnx, TestCategory!=SkipOnCIServer)

Closes #5046

🤖 Generated with Claude Code

rockfordlhotka and others added 3 commits November 20, 2026 14:11
The generated IDataPortalOperationMapping/IDataPortalOperationNamedMapping
code only covered operation methods the class declares, so operations on
a base class (a project base class or CSLA's own, such as
BusinessBase.Child_Create) threw DataPortalOperationNotSupportedException
from generated code before the data portal fell back to reflection.

Concrete classes now include the accessible, non-private operation
methods they inherit. Selection follows reflection-based dispatch: a
method closer to the class wins (scored as injected parameters less
inheritance depth), overrides without the attribute are called virtually
at the override's level, and an inherited method whose name the class
reuses is called through base. Methods that could bind to the wrong
overload, or that reflection could resolve differently, are still left
to reflection. Extension methods and the CSLADP002/CSLADP009 analyzers
still cover only declared methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Track whether a method is inherited separately from its dispatch depth,
  so overrides without the attribute (such as Child_Create) get no
  extension methods and no misplaced diagnostics.
- Report CSLADP002/CSLADP009 for collisions between a declared and an
  inherited method, at the declared method, so a cross-level tie that
  reflection reports as ambiguous is visible at build time.
- Leave methods whose signature uses a private or protected nested type
  out of the generated interface and dispatch; they made the generated
  code fail to compile (CS0051). Applies to declared methods as well.
- Require exact criteria types only between methods at the same level;
  guard a less specific declared method against criteria that match a
  method further up the chain instead, so it keeps handling other calls.
- Add inherited methods once per type in a separate pipeline step rather
  than for every operation method.
- Dispatch a lone params object[] operation method (the editable lists'
  Child_UpdateAsync) with the whole criteria array, as reflection does,
  when no other method of its kind exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Generated dispatch can select the wrong operation because it ignores unresolved candidates, excludes competing private signatures, omits injection-based scoring, and fails to recognize derived operation attributes.

4 open issues
What changed in this PR

Updates CSLA .NET’s data portal generator to dispatch supported inherited operation methods directly, reducing reflection fallbacks and debugger interruptions described in #5046.

Changes:

  • Adds inherited-method discovery and dispatch, including overrides, base calls, and lone params object[] operations.
  • Updates collision diagnostics and fallback handling while keeping generated extensions limited to declared operations.
  • Adds regression tests, snapshots, documentation, and a release note.
File Description
Source/​tests/​csla.netcore.test/​DataPortal/​InheritedOperationDispatchTests.cs Tests inherited root and child operations without fallback exceptions.
Source/​tests/​csla.netcore.test/​DataPortal/​DataPortalExtensionsTests.cs Resolves interface members against inherited methods.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.SingleFetchWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child-create dispatch.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.SingleCreateNoParams#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child-create dispatch.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.RunLocalAndValueTask#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside asynchronous operations.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.RootAndChildAttributes#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Includes the inherited member while preserving declared-method precedence.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.PrivateNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records fallback for private criteria types.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.PartialClassAcrossFiles#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch to a split partial class.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.ParamsArrayAndKeywordNames#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records whole-array criteria dispatch and inherited child creation.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.OperationWithInjectParam#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside injected parameters.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.OperationWithInjectAllowNull#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside nullable injection.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.NestedClass#TestApp.Outer.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch within a nested class.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.MultipleOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child creation alongside overloads.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.KeyedInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside keyed injection.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InjectBeforeCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside mixed parameter ordering.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedSameShapeAcrossLevels#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records guards for overlapping inherited criteria.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedProtectedNestedCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records fallback for protected criteria types.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItems.DataPortalOperations.g.verified.cs Records inherited list-update array dispatch.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedParamsArrayUpdateChild#TestApp.LineItem.DataPortalOperations.g.verified.cs Records inherited child creation for list items.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedOverriddenWithoutAttribute#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records virtual dispatch to unattributed overrides.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByIntermediate#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records fallback for intermediate-class hiding.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedOverloadHiddenByDerived#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records explicit base calls.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.Customer.DataPortalOperations.g.verified.cs Records dispatch from a constructed generic base.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedOperationsFromGenericBase#TestApp.AppBase_1.DataPortalOperations.g.verified.cs Records the abstract base’s declared-operation interface.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedOperationNameScoring#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Records cross-level winners and ambiguous fallbacks.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InheritedOperationNameScoring.verified.txt Records inherited-operation collision diagnostics.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.InCriteriaAndNullableInject#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside existing parameter cases.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.FileScopedNamespace#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch for file-scoped source.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.ExistingNamedMapping#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited criteria dispatch beside a custom named mapping.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.DuplicateOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child creation alongside duplicate names.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.DerivedFromBaseWithOperations#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child creation to the derived mapping.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.DeleteWithCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child-create dispatch.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.CompleteCrud#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside root operations.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.ChildOperations#TestApp.LineItem.DataPortalOperations.g.verified.cs Includes the inherited member while retaining declared child creation.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.AsyncMethod#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside asynchronous fetch.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.ArrayNullableGenericCriteria#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited dispatch alongside complex criteria types.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.AmbiguousOverloads#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child creation alongside overload guards.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​Snapshots/​DataPortalOperationsGeneratorTests.AmbiguousOperationName#TestApp.PersonEdit.DataPortalOperations.g.verified.cs Adds inherited child creation alongside ambiguous names.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalOperations/​DataPortalOperationsGeneratorTests.cs Adds inheritance, visibility, scoring, and array scenarios.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalExtensions/​Snapshots/​DataPortalExtensionsGeneratorTests.InheritedOperations#TestApp.PersonEdit.DataPortalExtensions.g.verified.cs Records extensions for declared operations only.
Source/​tests/​Csla.Generator.AutoImplementProperties.CSharp.Tests/​DataPortalExtensions/​DataPortalExtensionsGeneratorTests.cs Tests exclusion of inherited operations and overrides.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalOperations/​TrackingNames.cs Names the inherited-method pipeline stage.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalOperations/​OperationDiscovery.cs Discovers inherited methods and evaluates callable signatures.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalOperations/​Models/​OperationTypeModel.cs Tracks operation kinds with unresolved candidates.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalOperations/​Models/​OperationMethodModel.cs Adds inheritance, call-form, array, and visibility metadata.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalOperations/​IncrementalDataPortalOperationsGenerator.cs Adds inherited discovery after per-type grouping.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalOperations/​DataPortalOperationsBuilder.cs Emits inherited calls, selection guards, and array dispatch.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalOperations/​DataPortalOperationsAnalyzer.cs Reports inherited collisions at declared methods.
Source/​Csla.Generators/​cs/​AutoImplementProperties/​Csla.Generator.AutoImplementProperties.CSharp/​DataPortalExtensions/​IncrementalDataPortalExtensionsGenerator.cs Excludes inherited operations from extensions.
releasenotes.md Documents the inherited-dispatch fix.
docs/​data-portal-operations-generator.md Explains inheritance behavior and fallback cases.

Review effort: Balanced

Comment on lines +220 to +221
var all = model.Methods.Where(m => m.Kind == kind).ToList();
var ofKind = dispatchable.Where(m => m.Kind == kind).ToList();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in 50aa106.

Filtering the unresolved kinds out entirely would have dropped every generated call of that kind. Instead, inherited methods the generated code can't call now stay in the model with CanCall = false. That covers methods hidden by an intermediate member, methods that aren't accessible, and methods whose types the interface can't name. Because they stay in the model, operation-name selection and criteria dispatch still score them. In your example, the hidden Fetch(int) and Load(int) share Fetch__Int32 and tie, so neither is dispatched and reflection reports the ambiguity. InheritedOverloadHiddenByIntermediate now covers this.

Two cases still can't be modeled: generic operation methods, and declared methods marked with a subclass of an operation attribute. For those kinds UnresolvedKinds now skips both criteria and named dispatch, and the interface members stay in place for static references.

// When several methods at one level take the same number of
// criteria, require exact runtime types so a less specific overload
// cannot capture the call.
var requireExactTypes = ofKind.Count(m => m.CriteriaCount == method.CriteriaCount && m.InheritanceDepth == method.InheritanceDepth) > 1;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in 50aa106. Criteria dispatch now weighs a method against every other method of the kind with the same criteria count, including methods the generated code can't call. Those include methods with private or protected nested types, ref/out and params methods, and named-collision losers.

With Fetch(object) and Fetch(PrivateCriteria), the generated Fetch(object) branch now has !(criteria[0] is global::TestApp.PersonEdit.Criteria), so a Criteria value falls through to reflection, which picks the exact overload. This is in the PrivateNestedCriteria snapshot.

Comment on lines +244 to +246
var guards = requireExactTypes || HasExactCriteriaTypes(method)
? []
: sameShape.Where(m => m.InheritanceDepth > method.InheritanceDepth && !HasSameCriteriaTypes(m, method)).ToList();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the closer-method rule ignored injected parameters. Fixed in 50aa106 by replacing both the closer-method rule and the same-level exact-type rule with the scoring that ServiceProviderMethodCaller uses: exact type 3, assignable 2, object 1, minus inheritance depth, plus injected parameters.

For each other method of the same kind and criteria count, the generator compares the lowest score this method can get with the highest score the other can get.

  • The other can't reach it: no guard is added.
  • The other could tie or win unless the criteria match this method exactly: the branch gets !(matches other && !exact).
  • The other could tie or win regardless: the branch gets !(matches other). If the other covers every value this method accepts, the method is left out of criteria dispatch.
  • The generated code can't name the other method's types: the method falls back to requiring exact types, or to reflection.

Your example is the new InheritedInjectionScoring test. Fetch(int) (2) loses to Load(object, 4 × [Inject]) (3), so criteria dispatch calls Load for an int, as reflection does.

Named dispatch is unaffected. The client computes the operation name from the method reflection selects (TryGetProviderMethodInfoFor then ComputeOperationName in DataPortal<T>), so a name always identifies reflection's choice.

To keep the guards from adding noise, parameter models now record a type category and the types each one is assignable to. Guards are left out between types no value can match both, such as int and a class, or int[] and List<int>. Variant generic types and reference-type arrays are treated as possibly overlapping.

Comment on lines +394 to +397
if (IsOperationAttribute(attribute.AttributeClass))
{
var name = attribute.AttributeClass!.Name;
var kind = name.Substring(0, name.Length - "Attribute".Length);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: the operation attributes aren't sealed. Fixed in 50aa106.

  • Inherited methods: GetOperationKind walks the attribute's base types, so an inherited method marked with a subclass such as InitializeChildAttribute : CreateChildAttribute is discovered as CreateChild. It beats the more distant BusinessBase.Child_Create, as it does under reflection (InheritedDerivedOperationAttribute).
  • Declared methods: these are found by ForAttributeWithMetadataName on the exact attribute name, so a declared method with a subclassed attribute isn't modeled. Its kind is now marked unresolved, and all calls of that kind are left to reflection, which finds it (DeclaredDerivedOperationAttribute). Before this change the generated code would have called the inherited Child_Create instead.

Addresses PR review:

- Inherited methods the generated code cannot call (hidden by an
  intermediate member, inaccessible, or with types the interface cannot
  name) stay in the model, marked CanCall = false, so they compete when
  generated dispatch picks a method, instead of only marking the kind
  unresolved. Kinds that remain unresolved (generic methods, and declared
  methods marked with a subclass of an operation attribute) get no
  generated dispatch at all.
- Criteria dispatch compares, for every other method of the kind with the
  same criteria count, the lowest score the method can have with the
  highest score the other can have, using reflection's scoring (exact 3,
  assignable 2, object 1, minus inheritance depth, plus injected
  parameters). The method is guarded against criteria that match the
  other whenever the other could tie or win, or left to reflection when
  the generated code cannot test the other's types. This replaces the
  same-level exact-type rule and the closer-method rule, and accounts for
  injected parameters across levels.
- Parameter models record a type category and assignable types, so
  guards between types that no value can match both (int vs a class,
  int[] vs List<int>) are omitted. Variant generic types and reference
  arrays are treated as possibly overlapping.
- A subclass of an operation attribute counts as that attribute for
  inherited methods, as GetCustomAttributes<T>(true) does at runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rockfordlhotka
rockfordlhotka merged commit 2b40ef7 into main Nov 20, 2026
3 checks passed
@rockfordlhotka
rockfordlhotka deleted the issue-5046/generated-data-portal-mapping-throws-for-inherited branch November 20, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated data portal mapping throws for operation methods inherited from a base class

2 participants