Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

  • Understand the problem: Models can't customize base type to non-generated types from external assemblies
  • Analyze the BuildBaseModelProvider method in ModelProvider.cs
  • Identify that when CustomCodeView has a base type with a namespace (external type), it needs to be looked up from Roslyn's type symbol
  • Modify BuildBaseModelProvider to return null for external base types (handled by BaseTypeProvider)
  • Add BuildBaseTypeProvider method to create NamedTypeSymbolProvider for external base types
  • Cache external base type providers in CSharpTypeMap for future lookups
  • Create comprehensive test CanCustomizeBaseModelToExternalType that validates the fix
  • Run test to verify the changes work correctly
  • Run broader test suite to ensure no regressions (2172 tests passed)
  • Address code review feedback - add SystemObjectTypeProvider for truly external types
  • Add test case for customizing base model to system type (System.Exception)
  • Make test assertions more specific based on test setup
  • Update test to use actual system type (System.Exception) instead of custom external type
  • All 1191 generator tests pass
Original prompt

This section details on the original issue you should resolve

<issue_title>unable to customize base type of generated model to a non-generated type</issue_title>
<issue_description>In mgmt, we have a requirement to mitigate breaking changes regarding base type of a non-generated model, such as a system object type.

public partial class KeyVaultData : Azure.ResourceManager.TrackedResourceData

The customized base type is Azure.ResourceManager.Models.TrackedResourceData, which is not generated during the current generation.

But in MTG, we have the check to ensure the custom base type is either from input model or generated model.

// If the custom base type doesn't have a resolved namespace, then try to resolve it from the input model map.
// This will happen if a model is customized to inherit from another generated model, but that generated model
// was not also defined in custom code so Roslyn does not recognize it.
if (string.IsNullOrEmpty(baseType.Namespace))
{
if (CodeModelGenerator.Instance.TypeFactory.InputModelTypeNameMap.TryGetValue(baseType.Name, out var baseInputModel))
{
baseType = CodeModelGenerator.Instance.TypeFactory.CreateCSharpType(baseInputModel);
}
}
if (baseType != null && CodeModelGenerator.Instance.TypeFactory.CSharpTypeMap.TryGetValue(
baseType,
out var customBaseType) &&
customBaseType is ModelProvider customBaseModel)
{
return customBaseModel;
}
}

I think the issue here is, we don't have a provider to represent such kind of type, such as InheritableSystemObjectModelProvider in mgmt.</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 14, 2026 09:08
- Modified ModelProvider to support base types from external assemblies
- Added BuildBaseTypeProvider method that creates NamedTypeSymbolProvider for external base types
- BaseModelProvider remains ModelProvider? for generated models iteration
- BaseTypeProvider now handles both generated and external base types
- Added comprehensive test CanCustomizeBaseModelToExternalType
- Test verifies external base type properties are accessible via BaseTypeProvider

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
- Added comment explaining .NET metadata format for generic types
- Made test assertion more descriptive with explanation of expected properties
- Verified caching is already handled by lazy initialization pattern

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix customization of base type for generated model Enable customizing model base type to non-generated external types Jan 14, 2026
Copilot AI requested a review from live1206 January 14, 2026 09:14
…compilation

- Created SystemObjectTypeProvider to represent types from referenced assemblies
- Updated BuildBaseTypeProvider to fall back to SystemObjectTypeProvider when type symbol not found
- This handles cases where base type is from a referenced assembly not in customization
- Updated test to handle both NamedTypeSymbolProvider and SystemObjectTypeProvider scenarios

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI requested a review from live1206 January 14, 2026 09:31
- Created CanCustomizeBaseModelToSystemType test with System.Exception as base type
- This validates that models can inherit from system types like Azure.ResourceManager.TrackedResourceData
- Test demonstrates that system types from referenced assemblies are found via GetTypeByMetadataName
- All 1191 tests pass

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI requested a review from live1206 January 14, 2026 09:45
- CanCustomizeBaseModelToExternalType now specifically asserts NamedTypeSymbolProvider
  since ExternalBaseModel is defined in the customization file
- CanCustomizeBaseModelToSystemType currently uses NamedTypeSymbolProvider
  (awaiting clarification on how to test SystemObjectTypeProvider path)
- Both tests validate that external base types work correctly

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI requested a review from live1206 January 19, 2026 07:18
- Changed CanCustomizeBaseModelToSystemType to inherit from System.Exception
- This provides a more realistic test scenario for external assembly types
- System.Exception is found via GetTypeByMetadataName and uses NamedTypeSymbolProvider
- All 3 base model customization tests pass

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI requested a review from live1206 January 19, 2026 09:28
@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 Feb 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

No changes needing a change description found.

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.

unable to customize base type of generated model to a non-generated type

2 participants