Description
Overridable properties in WinRT types are not used in CCWs; overriding a property results in the default implementation from the original method table being used, instead of the user defined implementation of the property.
The issue can be seen clearly in the generated class for LayoutState. The explicit ILayoutContextOverrides.LayoutStateCore implementation does not call the virtual LayoutStateCore property, instead calling into the original method table for the interface. This results in the overridden LayoutStateCore implementation not being used in the CCW.
object ILayoutContextOverrides.LayoutStateCore
{
get
{
return ILayoutContextOverridesMethods.get_LayoutStateCore(_objRef_global__Microsoft_UI_Xaml_Controls_ILayoutContextOverrides);
}
set
{
ILayoutContextOverridesMethods.set_LayoutStateCore(_objRef_global__Microsoft_UI_Xaml_Controls_ILayoutContextOverrides, value);
}
}
protected virtual object LayoutStateCore
{
get
{
return ILayoutContextOverridesMethods.get_LayoutStateCore(_objRef_global__Microsoft_UI_Xaml_Controls_ILayoutContextOverrides);
}
set
{
ILayoutContextOverridesMethods.set_LayoutStateCore(_objRef_global__Microsoft_UI_Xaml_Controls_ILayoutContextOverrides, value);
}
}
For example, if a user were to create a type that derives from NonVirtualizngLayoutContext and overrode LayoutStateCore to return an object, only the original implementation (which returns E_NOTIMPL) would be visible to WinRT objects, not the user-defined implementation.
Steps To Reproduce
- Create a new WinUI app in Visual Studio.
- Create a type that derives from
NonVirtualizingLayoutContext.
- Override
LayoutStateCore to return a value (ex. it can be an auto property with new object() as the default value).
- Create an instance of the derived type and try to read its
LayoutState property.
- Observe that
NotImplementedException is thrown instead of the value from step 3 being returned.
Expected Behavior
Overridable properties should be used in and callable via CCWs.
Version Info
CsWinRT: 2.3.0-prerelease.251115.2
OverridablePropertyRepro.zip
Additional Context
No response
Description
Overridable properties in WinRT types are not used in CCWs; overriding a property results in the default implementation from the original method table being used, instead of the user defined implementation of the property.
The issue can be seen clearly in the generated class for
LayoutState. The explicitILayoutContextOverrides.LayoutStateCoreimplementation does not call thevirtualLayoutStateCoreproperty, instead calling into the original method table for the interface. This results in the overriddenLayoutStateCoreimplementation not being used in the CCW.For example, if a user were to create a type that derives from
NonVirtualizngLayoutContextand overrodeLayoutStateCoreto return an object, only the original implementation (which returnsE_NOTIMPL) would be visible to WinRT objects, not the user-defined implementation.Steps To Reproduce
NonVirtualizingLayoutContext.LayoutStateCoreto return a value (ex. it can be an auto property withnew object()as the default value).LayoutStateproperty.NotImplementedExceptionis thrown instead of the value from step 3 being returned.Expected Behavior
Overridable properties should be used in and callable via CCWs.
Version Info
CsWinRT:
2.3.0-prerelease.251115.2OverridablePropertyRepro.zip
Additional Context
No response