-
Notifications
You must be signed in to change notification settings - Fork 121
Description
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
LayoutStateCoreto return a value (ex. it can be an auto property withnew object()as the default value). - Create an instance of the derived type and try to read its
LayoutStateproperty. - Observe that
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.2
Additional Context
No response